Mail Archives: djgpp/1998/01/13/21:04:20
At 12:32 1/14/1998 +0100, Dr. András Sólyom wrote:
>One of my programs keep crashing on realloc() and I cannot find the
>reason. I am allocating and reallocating some million times and somehow
>some pointers in the program which were valid becomes invalid, usually
>having a value of 0x09000000). I have tried many things (like using one
>of DJ's malloc()'s, or compiling under linux with ElectricFence) to
>catch the error but without success. So for debugging I can try to catch
>the invalid pointers.
>Is there any way to check a pointer for validity before dereferencing
>it?
As an initial sanity check, you can see if the pointer value is less than
4096 (i.e. in the NULL page), or greater than `sbrk(0)'. However, I think
that DJGPP's allocation scheme may leave holes in the address space, so it
may happen that an invalid pointer passes both these tests.
You can also run under a debugger like GDB, and inspect things when a
SIGSEGV arrives. Symifying the traceback printed at the crash may also help.
Nate Eldredge
eldredge AT ap DOT net
- Raw text -