I use malloc to allocate 8192 bytes of memory; malloc returns successfully, but for some reason, I cannot access memory beyond 4205 bytes of that memory chunk.
I've also tried allocating even larger chunks of memory (i.e. 8192 * 2) but still no luck, only the first 4205 byes of memory is accessible :(
Here is the partial code:
int num_ino = 256; struct inode * ino_table = malloc(8192); assert(ino_table); for(int i = 0; i < num_ino; i ++){ printf("pre core dump %d\n", i); memcpy(ino_table + i * sizeof(struct inode), &inotable[i], sizeof(struct inode)); } Here is what happens in gdb:
Breakpoint 1, unixfilesystem_init (dfd=3) at unixfilesystem.c:54 54 assert(ino_table); (gdb) p *(ino_table) $1 = {i_mode = 0, i_nlink = 0 '\000', i_uid = 0 '\000', i_gid = 0 '\000', i_size0 = 0 '\000', i_size1 = 0, i_addr = {0, 0, 0, 0, 0, 0, 0, 0}, i_atime = {0, 0}, i_mtime = {0, 0}} (gdb) p *(ino_table + 4205) $2 = {i_mode = 0, i_nlink = 0 '\000', i_uid = 0 '\000', i_gid = 0 '\000', i_size0 = 0 '\000', i_size1 = 0, i_addr = {0, 0, 0, 0, 0, 0, 0, 0}, i_atime = {0, 0}, i_mtime = {0, 0}} (gdb) p *(ino_table + 8000) Cannot access memory at address 0x643a30 (gdb) p *(ino_table + 4206) Cannot access memory at address 0x625ff0
struct inode?struct inodebigger than acharin size?struct inode *ino_table = malloc(sizeof(struct inode) * 256);(gdb) x ino_table + i. You will see that as you increaseiby one, the address increases by more than one.