Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!bellcore!clyde!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: strcpy Message-ID: <13753@haddock.ima.isc.com> Date: 19 Jun 89 19:54:50 GMT References: <4400001@tdpvax> <13674@haddock.ima.isc.com> <2013@dataio.Data-IO.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 20 In article <2013@dataio.Data-IO.COM> bright@dataio.Data-IO.COM (Walter Bright) writes: >In article <13674@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes: >> memmove(dest, src, strlen(src)); > > memmove(dest, src, strlen(src) + 1); (I die. My replacement reads my uncommented code and deletes a fragment he doesn't understand. Eventually the subroutine is sold to the government, and the bug causes nuclear missles to be launched by accident. The other side retaliates, and all die. O the embarrassment.)% This is correct, of course; it only works to stop after strlen() if the receiving buffer is known to have a null character in the appropriate spot. Even if this were known information (e.g. if we're right-shifting a string in a null-padded buffer), it's cheaper to use the +1 than to document why it isn't necessary. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ________ % First person to identify the reference wins a defunct root password.