home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark
- From: ark@alice.att.com (Andrew Koenig)
- Newsgroups: comp.lang.c
- Subject: Re: Pointers outside of array boundary
- Message-ID: <23344@alice.att.com>
- Date: 29 Jul 92 04:22:30 GMT
- Article-I.D.: alice.23344
- References: <1992Jul28.180945.22332@hubcap.clemson.edu>
- Reply-To: ark@alice.UUCP ()
- Organization: AT&T Bell Laboratories, Liberty Corner NJ
- Lines: 21
-
- In article <1992Jul28.180945.22332@hubcap.clemson.edu> mjs@hubcap.clemson.edu (M. J. Saltzman) writes:
-
- > float x = malloc(10*sizeof(float));
- > --x;
-
- > My question is: Can anyone name an existing machine on which this code
- > could fail, or give a really convincing hypothetical argument why it
- > is a bad idea?
-
- The most fundamental reason is that it WILL fail in any implementation
- that rigorously checks for conformance with the Standard.
-
- A more practical reason: suppose you're on a machine where addresses are
- (segment,offset) pairs, such as on Intel hardware. Suppose further that
- the hardware checks for offset underflow or overflow in address arithmetic.
- Then it is entirely possible for malloc to return a pointer to the beginning
- of a segment and --x to cause it to underflow. Worse, the error might
- be detected only when you have the bad luck to call malloc at the wrong time.
- --
- --Andrew Koenig
- ark@europa.att.com
-