memcpy
Timothy Murphy
tim at maths.tcd.ie
Sat Sep 22 20:17:30 AEST 1990
In <18083 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>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);
I'm afraid I oversimplified my example.
The intention in unix unzip.c was to repeat *any* seqence,
not just a single character, eg
buf[0] = a;
buf[1] = b;
memcpy(buf+2, buf, 20);
is intended to set
buf[0] = buf[2] = buf[4] = ... = a;
buf[1] = buf[3] = buf[5] = ... = b;
Incidentally, it's been pointed out to me
that this problem has been fixed in more recent versions
of unix unzip.c .
--
Timothy Murphy
e-mail: tim at maths.tcd.ie
More information about the Comp.std.c
mailing list