delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/13/21:04:20

Date: Tue, 13 Jan 1998 18:02:00 -0800 (PST)
Message-Id: <199801140202.SAA28703@adit.ap.net>
Mime-Version: 1.0
To: "=?iso-8859-1?Q?=22Dr._Andr=E1s_S=F3lyom=22?=" <solyom AT eik DOT bme DOT hu>,
djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Q: How to check validity of a pointer?

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019