From: Kamalesh Babulal Date: Fri, 23 Jun 2023 09:40:00 +0000 (+0530) Subject: api: fix build warning X-Git-Tag: v3.1.0~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1e2f05442df27295411134dddca024d7398e55f;p=thirdparty%2Flibcgroup.git api: fix build warning 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 --- 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++;