Out-of-bounds pointers

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Oct 7 05:09:03 AEST 1989


In article <12570028 at hpclwjm.HP.COM> walter at hpclwjm.HP.COM (Walter Murray) writes:
-the wording of 3.3.6 might be misleading:  "Unless both the pointer
-operand and the result point to elements of the same array object,
-or the pointer operand points one past the last element of an array
-object and the result points to an element of the same array object,
-the behavior is undefined if the result is used as an operand of
-the unary * operator."  Doesn't this imply rather strongly that it
-IS legal to compute an invalid address, as long as it isn't
-dereferenced?

Not the way I read it in context, and certainly not the way it was
intended.  There are a lot of constraints on pointer arithmetic in
the same paragraph; the cited sentence is merely one more constraint.
It IS undefined behavior if you try to access some place outside the
actual array.  There are many other ways to obtain undefined behavior
during pointer arithmetic itself.



More information about the Comp.std.c mailing list