Out-of-bounds pointers
Scott Amspoker
scott at bbxsda.UUCP
Fri Oct 6 03:20:24 AEST 1989
In article <4199 at letni.UUCP> doug at letni.LawNet.Com (Doug Davis) writes:
>In article <1009 at mtxinu.UUCP> ed at mtxinu.COM (Ed Gould) writes:
>> void
>> f() {
>> char bug[100];
> ^^^^^^^^^^ I assume you mean buf here, right?
>> char *p;
>>
>> p = buf;
>>
>> p--; /* p contains an illegal value: &buf[-1] */
> ^^^ Opps, You have now entered the land of illegal addresses,
> normally called the twilight zone, incrementing the
> pointer is no longer guarenteed to be == &buf[0], that
> is installation dependent. Most likely it will == something
> really weird and you get a core dump. Which one you get
> is left as an exercise to the reader.
Agreed, it is undefined. However *most likely* it will work just fine (based
on the several dozen systems I've worked with). I would recommend avoiding
it though.
--
Scott Amspoker
Basis International, Albuquerque, NM
(505) 345-5232
More information about the Comp.std.c
mailing list