Garrett D'Amore wrote:
Hugh McIntyre wrote:
More to the point, the vanilla (non optimized) version of strcpy in
libc/port/gen/strcpy.c, and which has not changed since V7 Unix at
least, definitely won't work for overlapping strings for the case that
s1>s2:
while (*s1++ = *s2++)
;
I believe this implementation goes all the way back to actual K&R. Its
about as old as it gets for C.
Yes, it's unlikely any earlier implementation was different.
My gut feeling is that the existing bug should be closed "not-a-defect"
(if there is even a CR open for it), and Joerg (and any one else who has
code that made bad assumptions) needs to fix their code.
The comment earlier in the thread was that it was maybe worth restoring
the undocumented-but-correct behavior for the testcase Joerg saw,
because the failure was very subtle and might not get noticed by testing
(i.e. you'd get data corruption) whereas the traditional s1>s2 undefined
case is going to very visibly fail with a segmentation fault pretty quickly.
It's a pain in the neck to support this though, since any optimized
implementation is going to want to do 32bit or 64bit at-a-time copies
wherever possible, and the only way to be correct in this case is to
check "if (s2>s1 && (s2-s1 < 4)" or similar. For an OS which didn't
want to put 'if (s==NULL) s="(null)"' in printf() because of
performance, this seems irritating. However, sone of the optimized
version need to have similar start/end alignment tests.
Hugh.
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code