🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5748

Re: detecting invalid pointers

#5748
From: Joseph S. D. Yao
Date: Fri, 10 Mar 1989 16:07
23 lines
1291 bytes
In article <15495@cup.portal.com> Kevin_P_McCarty@cup.portal.com writes:
>Is there any guaranteed way to detect an out of range pointer,
>i.e., one which is supposed to point into an array but might not?
>     int  x[TABLESIZE];
>     int  *p;

How about something on the order of:
	if (q != (int *) NULL &&
	    (i = q - x) >= 0 && i < TABLESIZE &&
	    q == &x[i]) {
		...
	}

I don't really think that the first comparison against NULL is nece-
ssary, but feel free to contradict.  (I know I couldn't stop ya.)

	Joe Yao		jsdy@hadron.COM (not yet domainised??)
	hadron!jsdy@{uunet.UU.NET,dtix.ARPA,decuac.DEC.COM}
	Xarc,arinc,att,avatar,blkcat,cos,decuac,\
	dtix,ecogong,empire,gong,grebyn,inco,    \
	insight,kcwc,lepton,lsw,netex,netxcom,    >!hadron!jsdy
	paul,phw5,research,rlgvax,seismo,sms,    /
	smsdpg,sundc,telenet,uunet              /
Technical Details
Message-ID: <842@hadron.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!decuac!hadron!jsdy
References: <15495@cup.portal.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!decuac!hadron!jsdy
From: jsdy@hadron.UUCP (Joseph S. D. Yao)
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: detecting invalid pointers
Message-ID: <842@hadron.UUCP>
Date: 10 Mar 89 16:07:04 GMT
References: <15495@cup.portal.com>
Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao)
Distribution: usa
Organization: Hadron, Inc., Fairfax, VA
Lines: 23