Subject: Re: sbrk(0) dumps a core??
To: Emmanuel Dreyfus <firstname.lastname@example.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
Date: 03/03/2001 16:51:51
> Anyone can explain me why the following program dumps a core at mine?
> void *size = (void*)0x4000;
Some flags go up here. Casting a nonzero number to a pointer
> end = sbrk (0);
> printf ("end=0x%lx\n", (long)end);
> res = brk (size);
Whoa Nelly! You've just set the break to 0x4000; if you have any data
segment above that, it just went poof.
> printf ("brk(0x%lx) returned %d\n", (long)size, res);
For example, when printf tries to access stdio's internal data
structures (they are quite likely above 0x4000 on the architecture
you're using - you didn't say what it was).
You probably want size to be an int, and to write res = sbrk (size);.
7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B