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.
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@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.