c - malloc problem? -
hello use malloc() generate buffer buffer char*
buffer = (char*)malloc(chunksize+1); (k = 0; k < chunksize; k++) { buffer[k] = (char) (j+k); }
however, in debugger can see buffer[3] example char wrote in, buffer buffer empty(a lot of spaces). second time write stuff in buffer after free(buffer), shows the content wrote first time, , overwrite it. can tell me why? thank you!!
one problem might try print char
buffer printf
or equivalent? missing assign
buffer[chunksize] = 0;
so buffer not terminated. may have behind that, e.g '\r'
.
if on other hand buffer
doesn't represent string you, better use different base type, unsigned char
.
Comments
Post a Comment