home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12839 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  2.2 KB

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