🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #655

Re: Out-of-bounds pointers

#655
From: Henry Spencer
Date: Tue, 03 Oct 1989 16:28
16 lines
1135 bytes
In article <1009@mtxinu.UUCP> ed@mtxinu.COM (Ed Gould) writes:
>Is the following code conformant?  It's clear that it's not legal to
>dereference the pointer in its "illegal" state, but is the p++ line
>guaranteed to return it to a valid value? ...
>		p = buf;
>		p--;	/* p contains an illegal value: &buf[-1] */
>		p++;	/* hopefully, now p == &buf[0] */

The effect of the `p--' line is undefined, so all bets are off.  Pointer
arithmetic (not dereferencing) is guaranteed to be well-behaved when a
pointer just past the *end* of the array is involved, but no such promises
are made about pointers just before the *beginning*.  It may work; it may
dump core; it may yield random results.
-- 
Nature is blind; Man is merely |     Henry Spencer at U of Toronto Zoology
shortsighted (and improving).  | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
Technical Details
Message-ID: <1989Oct3.162801.5708@utzoo.uucp>
Path: arc1-ca.pugleaf.net!utzoo!henry
References: <1009@mtxinu.UUCP>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Out-of-bounds pointers
Message-ID: <1989Oct3.162801.5708@utzoo.uucp>
Organization: U of Toronto Zoology
References: <1009@mtxinu.UUCP>
Date: Tue, 3 Oct 89 16:28:01 GMT