Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Malloc issue or at least detecting bogus pointers?

2 views
Skip to first unread message

Lothar Behrens

unread,
Oct 5, 2011, 2:14:04 AM10/5/11
to
Hi,

I have cases where a pointer to something has a value = 0x7 and thus
it will crash. My question now is how to detect bogus pointers?

Is there anywhere a document pointing out what address areas my
application has and thus deriving validation rules more than this:

if (ptr != NULL) {
ptr->DoStuff();
}

I don't like to only add as there may be other bogus values:

if (ptr != NULL && ptr != 0x7) {
ptr->DoStuff();
}

Another thing is probably using a malloc library with access to a list
of known pointers where I can check against.

Thanks,

Lothar

Richard Kettlewell

unread,
Oct 5, 2011, 4:06:00 AM10/5/11
to
Lothar Behrens <lothar....@lollisoft.de> writes:
> I have cases where a pointer to something has a value = 0x7 and thus
> it will crash. My question now is how to detect bogus pointers?

There's no general way to do detect invalid pointers. You have a bug
somewhere in your program that results in this pointer having this
value. Tools such as valgrind or a static analyser can help find such
bugs.

--
http://www.greenend.org.uk/rjk/
0 new messages