[reSIProcate] Visual Studio 2005 compilation warnings of 1.4 branch
Adam Roach
adam at nostrum.com
Tue Dec 9 20:11:34 CST 2008
On 12/9/08 5:13 PM, Matthias Moetje wrote:
> Although this wrapper might seem a bit more complex, it can even improve
> performance (compared to strncpy alone) when copying small strings to
> large buffers,
But it will be markedly slower when copying strings into buffers that
are on the order of the correct size, which is by far the more common
case -- you end up scanning the string twice to comply with the behavior
specified for strcpy_s.
> An advantage with this approach is that this will stronger force
> us to check the result of the *_s functions in the code and take
> appropriate measures which is not the case with the strn* functions.
>
If you want an alternate model to emulate, you're far better off with
strlcpy -- you can perform the same checks as strcpy_s without the
performance penalty (and it doesn't null-fill the buffer like strncpy).
For unsupported platforms, you can pull in an implementation from here:
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/strlcpy.c?rev=1.11&content-type=text/x-cvsweb-markup
(And, if you need a strlcat:
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/strlcat.c?rev=1.13&content-type=text/x-cvsweb-markup)
/a
More information about the resiprocate-devel
mailing list