From 52e8daca0c0b53c61c31fe9ea058b08e6eb7c2b1 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Mon, 14 Oct 2019 17:38:03 +0200 Subject: [PATCH] Fix warning in test_escape_string MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (cherry picked from commit 737ffc08e2d9f3d3dda40a51329881085070863e) --- src/utils/common/common_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/common/common_test.c b/src/utils/common/common_test.c index 0959f637..0e061a13 100644 --- a/src/utils/common/common_test.c +++ b/src/utils/common/common_test.c @@ -221,9 +221,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); } -- 2.11.0