我的程序很简单,
...
#define TO_INT(a) (*(int *)a)
void *pool_head;
void *pool_tail;
...
pool_head = sbrk(BUF_LENGTH);
if (pool_head == (void *)-1) {
errno = ENOMEM;
return pool_head;
}
pool_tail = sbrk(0);
TO_INT(pool_head) = BUF_LENGTH * -1;
TO_INT((pool_tail - 3)) = BUF_LENGTH * -1;
当我调试它时,它显示:
Program received signal SIGSEGV, Segmentation fault.
在TO_INT((pool_tail - 3)) = BUF_LENGTH * -1;
pool_tail & pool_head 的值:
pool_tail = 0x805a000
pool_head = 0x804a000
如何解决?谢谢!