From 076ca04b2d24ff593949e32b299657e9747e7ab8 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Tue, 27 Apr 2021 16:50:53 +0000 Subject: [PATCH] tools: Fix strncpy() truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix the following strncpy() string truncation warning: In function ‘strncpy’, inlined from ‘parse_cgroup_spec’ at ../tools/tools-common.c:92:2: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 4096 equals destination size [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Tom Hromatka --- src/tools/tools-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/tools-common.c b/src/tools/tools-common.c index 211a49a9..4b0efa8b 100644 --- a/src/tools/tools-common.c +++ b/src/tools/tools-common.c @@ -89,8 +89,8 @@ int parse_cgroup_spec(struct cgroup_group_spec **cdptr, char *optarg, } while (temp && jpath, pathptr, FILENAME_MAX); - cdptr[i]->path[FILENAME_MAX-1] = '\0'; + strncpy(cdptr[i]->path, pathptr, FILENAME_MAX - 1); + cdptr[i]->path[sizeof(cdptr[i]->path) - 1] = '\0'; return 0; } -- 2.47.2