From: Ruben Kerkhof Date: Mon, 14 Oct 2019 15:38:03 +0000 (+0200) Subject: Fix warning in test_escape_string X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=737ffc08e2d9f3d3dda40a51329881085070863e;hp=a22c4260335616b7847e57ef638e0e29cd8cda05;p=collectd.git Fix warning in test_escape_string In function ‘test_escape_string’, inlined from ‘main’ at src/utils/common/common_test.c:384:3: src/utils/common/common_test.c:226:5: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] 226 | strncpy(buffer, cases[i].str, sizeof(buffer)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- diff --git a/src/daemon/common_test.c b/src/daemon/common_test.c index 285ad6a3..23fe1ede 100644 --- a/src/daemon/common_test.c +++ b/src/daemon/common_test.c @@ -215,9 +215,9 @@ DEF_TEST(escape_string) { }; for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { - char buffer[16]; + char buffer[16] = {0}; - strncpy(buffer, cases[i].str, sizeof(buffer)); + strncpy(buffer, cases[i].str, sizeof(buffer) - 1); OK(escape_string(buffer, sizeof(buffer)) == 0); EXPECT_EQ_STR(cases[i].want, buffer); }