原来以为未知的内存不可写,而读还是可以的,尽管读出的数据无效,但是今天发现free过的内存读的时候段错误,颠倒了俺的人生观.
测试发现没有初始化的指针读取时也是段错误
#include <stdio.h>
int main( void )
{
char *p;
printf( "%s\n", p );
return 0;
}
root@zyjun:~# l
0.c 1/ 1.txt fdlogin/ heap.c heap.h main* qemu-2.0.0/ sqlite3_pc/ test.c ver2-1029/ zyj.sh* zyjun/ 网络编程/ 下载/ 桌面/
root@zyjun:~# cc 0.c
root@zyjun:~# l
0.c 1/ 1.txt a.out* fdlogin/ heap.c heap.h main* qemu-2.0.0/ sqlite3_pc/ test.c ver2-1029/ zyj.sh* zyjun/ 网络编程/ 下载/ 桌面/
root@zyjun:~# ./a.out
段错误 (核心已转储)
root@zyjun:~#