home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.lang.c
- Subject: Re: strcpy implementation question
- Message-ID: <14222@goanna.cs.rmit.oz.au>
- Date: 27 Aug 92 09:11:14 GMT
- References: <PINKAS.92Aug21114508@caraway.intel.com> <9224017.23144@mulga.cs.mu.OZ.AU>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 39
-
- In article <9224017.23144@mulga.cs.mu.OZ.AU>, fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- > ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
- > >This is wrong. It isn' the source or the destination that cares, it is
- > >strcpy() that cares. strcpy() MUST NOT READ any uninitialised memory
- > >locations.
- >
- > I'm sorry, but this is wrong.
- > The code to implement strcpy() does NOT have to be ansi-conformant - hell,
- > it doesn't even have to be written in C!
-
- The *implementation* of strcpy() can do anything it XXXing well pleases.
- The point I am making is that in the "model machine" it is not legal to
- refer to uninitialised locations. That is, the behaviour of strcpy()
- -- however it is implemented -- must not be distinguishable from the
- behaviour of a a "model" implementation which does not touch uninitialised
- locations. It must not be detectable that strcpy() has read any uninitiliased
- locations. Let me see if I can make the argument a little clearer.
-
- Suppose I have a destination array, allocated by the compiler, and of known
- size. Suppose I have already initialised all the elements of that array,
- somehow.
-
- static char a[48];
-
- This is by definition initialised to 0, so every element of this array is in
- a defined state. Now suppose I do
-
- strcpy(a, "foobarglezorch");
-
- This involves moving a defined sequence of characters to an area which is
- quite big enough for it and which does not overlap the source. The effect
- of strcpy() _isn't_ defined when source and destination overlap, but when
- they don't overlap, a[] should still be completely defined afterwards. One
- way of understanding this is that the "model" strcpy() should never read
- undefined characters, or you'd get undefined behaviour.
-
- Put it this way, the destination ALWAYS cares.
- --
- You can lie with statistics ... but not to a statistician.
-