[PATCH] lib: fwts_framework: use strlcpy instead of strncpy, fixes gcc-10 build errors
Colin King
colin.king at canonical.com
Mon Nov 4 11:52:39 UTC 2019
From: Colin Ian King <colin.king at canonical.com>
In function ‘fwts_framework_strtrunc’,
inlined from ‘fwts_framework_minor_test_progress’ at fwts_framework.c:470:3:
fwts_framework.c:374:3: error: ‘strncpy’ output may be truncated copying between 0 and 247 bytes from a string of length 1023 [-Werror=stringop-truncation]
374 | strncpy(dest, src, max);
| ^~~~~~~~~~~~~~~~~~~~~~~
In function ‘fwts_framework_strtrunc’,
inlined from ‘fwts_framework_run_test.isra’ at fwts_framework.c:596:4:
fwts_framework.c:374:3: error: ‘strncpy’ specified bound 1024 equals destination size [-Werror=stringop-truncation]
374 | strncpy(dest, src, max);
| ^~~~~~~~~~~~~~~~~~~~~~~
In function ‘fwts_framework_strtrunc’,
inlined from ‘fwts_framework_run_test.isra’ at fwts_framework.c:695:4:
fwts_framework.c:374:3: error: ‘strncpy’ specified bound 1024 equals destination size [-Werror=stringop-truncation]
374 | strncpy(dest, src, max);
| ^~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_framework.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 698fa49a..8bc7b0e0 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -26,6 +26,7 @@
#include <ctype.h>
#include <time.h>
#include <getopt.h>
+#include <bsd/string.h>
#include <sys/utsname.h>
#include <sys/time.h>
@@ -371,9 +372,9 @@ static void fwts_framework_show_tests(fwts_framework *fw, const bool full)
static void fwts_framework_strtrunc(char *dest, const char *src, size_t max)
{
if (src) {
- strncpy(dest, src, max);
+ strlcpy(dest, src, max);
if ((max > 3) && (strlen(src) > max)) {
- dest[max-1] = 0;
+ dest[max-1] = '\0';
dest[max-2] = '.';
dest[max-3] = '.';
}
--
2.20.1
More information about the fwts-devel
mailing list