我使用malloc分配8192字节的内存;malloc 成功返回,但由于某种原因,我无法访问超出该内存块 4205 字节的内存。
我还尝试分配更大的内存块(即 8192 * 2),但仍然没有运气,只能访问前 4205 个字节的内存:(
这是部分代码:
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));
}
以下是 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