memcpy

Karl Heuer karl at haddock.ima.isc.com
Fri Sep 21 03:55:56 AEST 1990


In article <1990Sep19.021418.11574 at maths.tcd.ie> tim at maths.tcd.ie (Timothy Murphy) writes:
>In [unix] unzip.c it is assumed that the effect of
>	buf[0] = c;
>	memcpy(buf+1, buf, 20);
>is to set
>	buf[0] = buf[1] = buf[2] = ... = buf[21] = c.

This is incorrect.  The proper way to achieve that effect is
	memset(buf, c, 21);

>Is this a bug on the Sparc [which doesn't do this],
>or is memcpy not fully specified?

The latter.  The effect of memcpy() on overlapping arrays is undefined.
(There is a new function memmove() which does have predictable behavior.)

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.std.c mailing list