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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -