From e1e2f05442df27295411134dddca024d7398e55f Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Fri, 23 Jun 2023 15:10:00 +0530 Subject: [PATCH] api: fix build warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix a build warning: cgcreate.c: In function ‘create_systemd_scope’: cgcreate.c:81:17: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation] 81 | strncpy(slice, cg->name, len); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cgcreate.c:80:23: note: length computed here 80 | len = strlen(cg->name) - strlen(scope); fix it by using, length of destination in the strncpy(). Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/tools/cgcreate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cgcreate.c b/src/tools/cgcreate.c index 589d72af..aad4092b 100644 --- a/src/tools/cgcreate.c +++ b/src/tools/cgcreate.c @@ -78,7 +78,7 @@ static int create_systemd_scope(struct cgroup * const cg, const char * const pro goto err; } len = strlen(cg->name) - strlen(scope); - strncpy(slice, cg->name, len); + strncpy(slice, cg->name, FILENAME_MAX - 1); slice[len] = '\0'; scope++; -- 2.47.2