msvcrt: strncpy doesn't compliant C standard (try 3)

Álvaro Nieto alvaro.nieto at gmail.com
Thu Aug 8 12:32:40 CDT 2013


Thank you for your feedback. I'll adjust the tests with your comments and
I'll try to use testbot.


2013/8/8 Dan Kegel <dank at kegel.com>

> Minor problem:
>
> +static void test_strncpy(void)
> +{
> +    size_t len = 10;
> +    char *ret;
> +    char dst[len + 1];
>
> Hmm.  That last line is a VLA, and might not compile in all C
> compilers because it's not allowed in C89.
> http://stackoverflow.com/questions/448844/variable-sized-arrays-in-c
> Wine seems to want to build in c89 compilers:
> http://www.winehq.org/pipermail/wine-cvs/2011-April/076721.html
>
> Try using a #define with a more unique name for the length instead,
> or better yet, replace len=10 with len=sizeof(dst)-1 or something.
>
> Larger problem:
>
>     ret = strncpy(dst, not_null_less, len);
>
> This is ill-defined.  You're copying 10 bytes from a 5 byte buffer.
> Don't do that.
>
> Also, passing a not-null-terminated string in as a special test case
> doesn't seem interesting... just pass in the longer null-terminated
> string, and specify a shorter length.  Fewer test strings needed,
> easier to read code.
>
> Please run 'make check', and test using http://testbot.winehq.org,
> before submitting patches.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20130808/18218104/attachment.html>


More information about the wine-devel mailing list