From 5216c713d0863a99f96abd40add7bb6e47bb9a18 Mon Sep 17 00:00:00 2001 From: Tom Barbette Date: Mon, 31 Aug 2020 11:38:56 +0200 Subject: [PATCH] Fix compiler error Recent GCC (9.3 at least) got smarter and sees that strncopy should not be used with its own length, and memcpy should be used instead. The error: In function strncpy, inlined from LoadConfig at ../common/applib.c:127:4: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: __builtin_strncpy output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../common/applib.c: In function LoadConfig: ../common/applib.c:124:15: note: length computed here 124 | if ((len = strlen(p)) > CONF_VALUE_LEN) --- samples/common/applib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/common/applib.c b/samples/common/applib.c index 3374f81..a81eaf4 100644 --- a/samples/common/applib.c +++ b/samples/common/applib.c @@ -124,7 +124,7 @@ LoadConfig(char *file_name, struct conf_var *vlist, int size) if ((len = strlen(p)) > CONF_VALUE_LEN) break; - strncpy(vlist[i].value, p, len); + memcpy(vlist[i].value, p, len); vlist[i].value[len] = '\0'; } }