Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!att!chinet!kdb From: kdb@chinet.chi.il.us (Karl Botts) Newsgroups: comp.std.c Subject: Re: ANSI C, hardware protection, out-of-bounds pointers Message-ID: <9520@chinet.chi.il.us> Date: 8 Sep 89 09:25:30 GMT References: <427@maytag.waterloo.edu> <1989Sep5.175411.25203@utzoo.uucp> Reply-To: kdb@chinet.chi.il.us (Karl Botts) Organization: Chinet - Public Access Unix Lines: 14 >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.