ANSI C, hardware protection, out-of-bounds pointers
Joseph S. D. Yao
jsdy at hadron.UUCP
Sat Sep 9 03:15:23 AEST 1989
In article <10970 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
-In article <867 at hadron.UUCP> jsdy at hadron.UUCP (Joseph S. D. Yao) writes:
->- char *head=a-1; /* Here! */
->This, too, is an out-of-bounds pointer, and is covered by the same
->rule. Nothing says that an OOB ptr has to be positively offset.
-Sorry, Joe, but you're wrong. Only the last+1 OOB pointer is legal,
-not the first-1. I've seen this fail in practice (in AT&T's UNIX
-implementation of bsearch(), as I recall) when the array element
-was fairly large and first-1 happened to wrap around the address
-space.
Erk. You're right. On the other hand (since stacks don't HAVE to be
at the end of data space), an array could also abut the end of data
space, and thus last+1 becomes NULL. Is there anything forbidding
that?
For that matter, is there anything IN THE STANDARD that says first-1 is
illegal? (Besides the general fact that it's bad practice, of course.)
Joe Yao
More information about the Comp.std.c
mailing list