From: Ruben Kerkhof Date: Mon, 14 Oct 2019 16:12:52 +0000 (+0200) Subject: Fix warning in test_strunescape X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7109b8a27f2d82fbf8c1ae9d58ab6cffbaec9339;p=collectd.git Fix warning in test_strunescape src/utils/common/common_test.c:254:3: warning: ‘strncpy’ output truncated before terminating nul copying 16 bytes from a string of the same length [-Wstringop-truncation] 254 | strncpy(buffer, "\\tbackslash end\\", sizeof(buffer)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CCLD test_common (cherry picked from commit 5bcc3a10cbae9d94ccb10a62218ab26433bbaa67) --- diff --git a/src/utils/common/common_test.c b/src/utils/common/common_test.c index 0e061a13..b8b3b4f7 100644 --- a/src/utils/common/common_test.c +++ b/src/utils/common/common_test.c @@ -232,33 +232,33 @@ DEF_TEST(escape_string) { } DEF_TEST(strunescape) { - char buffer[16]; + char buffer[32] = {0}; int status; - strncpy(buffer, "foo\\tbar", sizeof(buffer)); + strncpy(buffer, "foo\\tbar", sizeof(buffer) - 1); status = strunescape(buffer, sizeof(buffer)); OK(status == 0); EXPECT_EQ_STR("foo\tbar", buffer); - strncpy(buffer, "\\tfoo\\r\\n", sizeof(buffer)); + strncpy(buffer, "\\tfoo\\r\\n", sizeof(buffer) - 1); status = strunescape(buffer, sizeof(buffer)); OK(status == 0); EXPECT_EQ_STR("\tfoo\r\n", buffer); - strncpy(buffer, "With \\\"quotes\\\"", sizeof(buffer)); + strncpy(buffer, "With \\\"quotes\\\"", sizeof(buffer) - 1); status = strunescape(buffer, sizeof(buffer)); OK(status == 0); EXPECT_EQ_STR("With \"quotes\"", buffer); /* Backslash before null byte */ - strncpy(buffer, "\\tbackslash end\\", sizeof(buffer)); + strncpy(buffer, "\\tbackslash end\\", sizeof(buffer) - 1); status = strunescape(buffer, sizeof(buffer)); OK(status != 0); EXPECT_EQ_STR("\tbackslash end", buffer); return 0; /* Backslash at buffer end */ - strncpy(buffer, "\\t3\\56", sizeof(buffer)); + strncpy(buffer, "\\t3\\56", sizeof(buffer) - 1); status = strunescape(buffer, 4); OK(status != 0); OK(buffer[0] == '\t');