Re: Validate a pointer
From: Måns Rullgård (mru_at_inprovide.com)
Date: 12/11/04
- Next message: William Park: "Re: some more bash help please"
- Previous message: Ara.T.Howard_at_noaa.gov: "Re: Validate a pointer"
- In reply to: Ara.T.Howard_at_noaa.gov: "Re: Validate a pointer"
- Next in thread: Bryan Bullard: "Re: Validate a pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 11 Dec 2004 22:34:02 +0100
Ara.T.Howard@noaa.gov writes:
> On Sat, 11 Dec 2004, [iso-8859-1] Måns Rullgård wrote:
>
>> Rich Teer <rich.teer@rite-group.com> writes:
>>
>>> As someone else suggested, if you want to know if a pointer is
>>> valid or not, arrange to trap the apprpriate signals, and handle
>>> them as you see fit.
>>
>> Don't do that. The signal may only be triggered after God knows what
>> damage has been done. Any (all) your data may have been trashed
>> before you hit an unmapped address.
>
> in some cases you might be able to simply fork and then dereference
> the pointer - the memory you trash will be the memory of the child
> unless you are doing something like mmap, etc. this is also quite
> expensive but, in some systems, not as much as it once was: perhaps
> equal to creating a thread. i guess it depends on how important and
> how often one would do this.
My point was that by the time you decide to dereference your possibly
invalid pointer, lots of data might have be trampled on. Likely areas
are your stack, in which case your program will anyway crash when the
current function returns.
There are no shortcuts to writing good code. Start with a good
design, implement it well, and you'll know which pointers are valid
without testing them.
-- Måns Rullgård mru@inprovide.com
- Next message: William Park: "Re: some more bash help please"
- Previous message: Ara.T.Howard_at_noaa.gov: "Re: Validate a pointer"
- In reply to: Ara.T.Howard_at_noaa.gov: "Re: Validate a pointer"
- Next in thread: Bryan Bullard: "Re: Validate a pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|