Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!ico!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.std.c Subject: Re: memcpy Keywords: memcpy Message-ID: <18083@haddock.ima.isc.com> Date: 20 Sep 90 17:55:56 GMT References: <1990Sep19.021418.11574@maths.tcd.ie> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 17 In article <1990Sep19.021418.11574@maths.tcd.ie> tim@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@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint