strcat+strcat+strcat == baaad
Shachar Shemesh
wine-devel at sun.consumer.org.il
Mon Dec 2 05:45:50 CST 2002
David Laight wrote:
>Inlining them would (probably) be bad news. They are not
>a completely trivial size (ie smaller than the call sequence)
>and they are more likely to be resident in the Icache if they
>are functions.
>
Yes, but they are much more likely to fit into the function scope
optimization if they are inlined.
>They are useful though, and do what the programmer wanted
>(unlike strncpy whose only point is that it doesn't overrun
>the target buffer).
>
>However in this case they aren't quite right!
>
> len = strlcpy(buf, s0, buflen);
> len += strlcpy(buf + len, s1, buflen - len)
> len += strlcpy(buf + len, s2, buflen - len)
>
ahem. The code should be:
strlcpy(buf, s0, buflen);
strlcat(buf, s1, buflen);
strlcat(buf, s2, buflen);
If you are going to be sliding the buffer with each call, then you can
just as well use your functions.
>is slightly more complex than using my str_add().
>
>The source for the functions can be grabbed from netbsd or freebsd.
>
> David
>
>
>
More information about the wine-devel
mailing list