Date: Sat, 23 Jun 2001 16:17:36 -0400 (EDT) From: Zhihui Zhang <zzhang@cs.binghamton.edu> To: freebsd-questions@freebsd.org Subject: sbrk() and segment fault Message-ID: <Pine.SOL.4.21.0106231610180.23292-100000@opal>
next in thread | raw e-mail | index | archive | help
Out of curiosity, I tried the following program on FreeBSD 4.3-Release: #include <stdio.h> #include <unistd.h> main() { char * ret, * endpt; endpt = sbrk(0); printf("endpt = %x after sbrk\n", (int)endpt); #if 1 ret = brk(endpt); if (ret == (char *) -1) { printf("brk of %x failed\n", endpt); exit(0); } #endif printf("brk of %x succeed\n", (int)endpt); } dell# cc sbrk2.c; a.out endpt = 8049708 after sbrk Segmentation fault (core dumped) If I change #if 1 to #if 0, then it runs OK. So why brk() to the SAME address can cause problem? Is it some roundup done in obreak() in vm_unix.c? Or maybe my understanding of break is not complete. Thanks for any help. -Zhihui To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.4.21.0106231610180.23292-100000>