ANSI C, hardware protection, out-of-bounds pointers

Karl Botts kdb at chinet.chi.il.us
Fri Sep 8 19:25:30 AEST 1989


>High-end out-of-bounds pointers are very common, and all an implementation
>usually has to do to make them work is to ensure that the end of the array
>is at least one byte below a segment boundary (assuming that the hardware
>has segments), so that a high-end pointer is still in the same linear
>address space as a normal one and address arithmetic therefore works as
>expected.  Low-end out-of-bounds pointers are much less common, and making

The following is in no way guaranteed by ANSI C, but I think it something
you can depend on pretty solidly.  Any standard implementation of malloc()
et al. puts either the size of the block or a pointer to the next block in
the machine word just before the start of the block; this will be in the
same linear address space.  Thus you can be sure that mentioning this word
(or even dereferencing it) will not cause an exception.  Of course this
only holds true for malloc()ed blocks.



More information about the Comp.std.c mailing list