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

Dan Kegel dank at kegel.com
Wed Aug 7 20:25:21 CDT 2013


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.



More information about the wine-devel mailing list