samedi 28 février 2015

Address is 0 bytes after a block of size 1,024 alloc'd

I ran valgrind on my program and it told me there an address is of size 0 after alloc-ing 1024 bytes. The code:



unsigned char *dir_buf = malloc(1024 * sizeof(unsigned char));
assert(dir_buf);


The log:



==30231== Address 0x51fd540 is 0 bytes after a block of size 1,024 alloc'd
==30231== at 0x4C2ABA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30231== by 0x40153C: do_pass1 (pass1.c:25)
==30231== by 0x4019EC: do_pass1 (pass1.c:144)
==30231== by 0x401B0F: pass1 (pass1.c:184)
==30231== by 0x4010E8:
main (blah.c:225)


Any idea why? I'm getting an invalid read size of 4 when I use that pointer.



dir = (struct ext2_dir_entry_2 *)(dir_buf);
if(dir->inode == 0) break; //INVALID READ

Aucun commentaire:

Enregistrer un commentaire