strcpy wars, jeez! A proposed resolution.

00704a-Liber nevin1 at ihlpf.ATT.COM
Sat Apr 2 08:42:15 AEST 1988


In article <3267 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <4215 at ihlpf.ATT.COM> nevin1 at ihlpf.UUCP (00704a-Liber,N.J.) writes:
>>If this were to change, all programs that use strcpy() would be suspect every
>>time a new version of the compiler comes out
>
>Only those programs that use strcpy on overlapping strings.  And if the
>"implementation-defined" part is properly phrased, strcpy(s,s+1) would be
>guaranteed to be safe.

First off, just by looking at a program how can I tell whether or not it
uses overlapping strings (under your proposal)??  There is no way for me to
tell the difference between a program that is using strcpy() in an
implementation-DEPENDENT way and a program which can portably use
strcpy() (at least not by just looking at it).  From a maintenance point of
view, this is very undesirable!!

Secondly, I do not like the change that would have to be made to the
prototype for strcpy.  The prototype would change from:

char *strcpy(noalias char *s1, const noalias char *s2)

to

char *strcpy(char *s1, char *s2)

since, as you pointed out, both s1 and s2 are possibly aliased and the
string pointed to by s2 is no longer guaranteed to be constant (see below).

char *foo, *bar;
...
/*assume that foo points to string "stuff" in read/write memory*/
bar = foo + 1;
strcpy(foo, bar);

Under your proposal, this would *legally* change the value of what bar points
to (unless you are going to put in some wording about only being able to
copy the right half or less of overlapping strings, but this wording is
VERY messy)!!  I'm sorry, but I like knowing that the source string should
not be changed by strcpy() in a conforming program!!


In article <3266 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
>I don't see that such a compiler would have to depend on the implementation;
>just on the functional specification (which has now been standardized).

MAKE UP YOUR MIND!!  You either want to have programs which are dependent
on the implementation of the libraries or you don't.  I don't really care
which of these two views that you take, JUST BE CONSISTENT!!
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah



More information about the Comp.lang.c mailing list