Archived

This topic is now archived and is closed to further replies.

gimp

After mallocing I see ÿÿÿÿ after data...

Recommended Posts

I''m using MSVC++ I malloc out a hunk of ram, say 4 bytes and see the new uninitialized hunk of ram appear in the debugger as: ÍÍÍÍÿÿÿÿ What''s with that? I zero the memory and it disappears. I memcpy in a value in to those 4 bytes and now I see abcdÿÿÿÿ sizeof() = 4... Whats going on? I didn''t used to see that when I used statically defined character arrays but when I use a malloc''ed hunk of ram I get this? What does this mean?

Share this post


Link to post
Share on other sites
ok dude....

when it creates the memory... it reserves a location in memory... it doesn''t do anything with it so the memory contains what ever was there before... when you zero it out it clears the memory...

when msvc displays a string it goes until it gets a NULL byte terminating the string... when you memcopied the string you probably didn''t place a NULL byte at the end... and because you overwrote the NULL bytes in the string it doesn''t see the end of the string... and it keeps going.... try making your string one more byte in length and then zero it out... or otherwise make sure a NULL is placed at the end

Great Milenko

Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."


http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech

Share this post


Link to post
Share on other sites
If you know that the place you are copying from is a string already you maky your array the size of the string +1 and memcpy size of string+1 Or as previous post said just put a ''/0'' character in the last memory location for the string.

Share this post


Link to post
Share on other sites
quote:
Original post by Neuro

If you know that the place you are copying from is a string already you maky your array the size of the string +1 and memcpy size of string+1 Or as previous post said just put a ''/0'' character in the last memory location for the string.


It''s not ''/0'' it''s ''\0''

/. Muzzafarath
Mad House Software

Share this post


Link to post
Share on other sites
Sorry, your correct. That what comes to having 3 unix shells open on your desktop.

it is ''\0'' just like it is ''\n'' and ''\\'' and so on...

Apart from that error, everything else is correct.

Share this post


Link to post
Share on other sites