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