From 0f26279b1a297c2ebf3157fcb6e16c86e30c7270 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Mon, 14 Oct 2019 18:12:52 +0200 Subject: [PATCH] Fix warning in test_strunescape MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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) (cherry picked from commit 7109b8a27f2d82fbf8c1ae9d58ab6cffbaec9339) --- src/utils/common/common_test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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'); -- 2.11.0