From 6670a5272d371fcfc55801b5114b6bdc6f70b017 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Mon, 14 Oct 2019 17:36:55 +0200 Subject: [PATCH] Fix warning in test_escape_slashes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (cherry picked from commit a22c4260335616b7847e57ef638e0e29cd8cda05) (cherry picked from commit d5edf1e82feb80cfe90cfa35501eef3c8dc493e5) --- 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 4f15c16f..0959f637 100644 --- a/src/utils/common/common_test.c +++ b/src/utils/common/common_test.c @@ -196,9 +196,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); } -- 2.11.0