From: Florian Forster Date: Thu, 21 Dec 2023 11:05:45 +0000 (+0100) Subject: common: Fix compiler warning in unit test. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e96ff0883e09eaa7275f03ff01077d26ca556b34;p=thirdparty%2Fcollectd.git common: Fix compiler warning in unit test. Some compilers complained about using a value that depends on the input for the size argument passed to `strncpy`. They missed that the size of `buf` also depends on the source argument and therefore this use is fine. ``` CC src/utils/common/common_test.o ../../src/utils/common/common_test.c: In function 'test_parse_values': ../../src/utils/common/common_test.c:316:5: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 316 | strncpy(buf, cases[i].buffer, buf_sz); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/utils/common/common_test.c:314:21: note: length computed here 314 | size_t buf_sz = strlen(cases[i].buffer) + 1; | ^~~~~~~~~~~~~~~~~~~~~~~ ``` --- diff --git a/src/utils/common/common_test.c b/src/utils/common/common_test.c index 7da7c0138..7a1d53931 100644 --- a/src/utils/common/common_test.c +++ b/src/utils/common/common_test.c @@ -313,7 +313,7 @@ DEF_TEST(parse_values) { size_t buf_sz = strlen(cases[i].buffer) + 1; char buf[buf_sz]; - strncpy(buf, cases[i].buffer, buf_sz); + strncpy(buf, cases[i].buffer, sizeof(buf)); int status = parse_values(cases[i].buffer, &vl, &ds); EXPECT_EQ_INT(cases[i].status, status);