strcpy

Walter Bright bright at Data-IO.COM
Sat Jun 17 04:50:19 AEST 1989


In article <13674 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
<If you want to copy overlapping strings, you should probably use
<	memmove(dest, src, strlen(src));
<since memmove() does have predictable behavior on overlap.

I get involved with helping people debug C code from time to time, and the
bug in the above code occurs frequently. I.e., the line should be:
	memmove(dest, src, strlen(src) + 1);
I'm pointing this out because it's such a common bug that it's one of the
things I routinely look for. Remember:
	static char src[] = "abc";
	sizeof(src) == 4
	strlen(src) == 3



More information about the Comp.lang.c mailing list