🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #653

Out-of-bounds pointers

#653
From: Ed Gould
Date: Tue, 03 Oct 1989 01:01
21 lines
846 bytes
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?  What would it (be expected
to) print?


	void
	f() {
		char bug[100];
		char *p;

		p = buf;

		p--;	/* p contains an illegal value: &buf[-1] */
		p++;	/* hopefully, now p == &buf[0] */

		if(p == buf)
			printf("It worked\n");
		else
			printf("It failed\n");
	}
Technical Details
Message-ID: <1009@mtxinu.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mtxinu!mtxinu.COM!ed

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mtxinu!mtxinu.COM!ed
From: ed@mtxinu.COM (Ed Gould)
Newsgroups: comp.std.c
Subject: Out-of-bounds pointers
Message-ID: <1009@mtxinu.UUCP>
Date: 3 Oct 89 01:01:38 GMT
Sender: ed@mtxinu.COM
Reply-To: ed@mtxinu.COM (Ed Gould)
Organization: mt Xinu, Berkeley
Lines: 21