Re: generic strncpy - off-by-one error

Timothy Miller
2003-08-18T16:01:21Z

Daniel Forrest wrote:
> On Sat, Aug 16, 2003 at 10:15:14AM +0200, Peter Kjellerstedt wrote:

> Shouldn't this be:
>
> while (tmp & (sizeof(long) - 1)) {
>
>
>> *tmp++ = '\0';
>> count--;
>> }

Oh, yeah! That's right. We need to check the address. Also need to
cast tmp to (int) or something (doesn't matter what it's cast to,
because we only care about the lower 2 or 3 bits).

Peter, please see if this makes any speed difference. But it definately
needs this fix.

Frankly, I'm surprised it works. In fact, it might not, but it's hard
to tell from the tests just benchmarks.

Also, if you're doing dense addressing on Alpha, and you do byte
accesses the addresses for char are byte addresses, but the code does
read-modify-write to memory for byte accesses, because in that mode, you
can only do 32-bit and 64-bit accesses. The performance increase could
be even greater for Alpha than for x86.

For Sparc, we might be able to do something with VIS instructions,
although I don't know what the setup overhead is. Sun's memcpy and
memset only use VIS when the size is greater than 512, because
otherwise, it's not worth it.

I don't know enough about PowerPC other than the proper use of the
"eieio" instruction. :)