]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: fix build warning
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 23 Jun 2023 09:40:00 +0000 (15:10 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 26 Jun 2023 15:56:22 +0000 (09:56 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgcreate.c

index 589d72afd80189573d7f083030c6160dffc750c3..aad4092bc5f9ec2b2cfe8deda6c4a825d436fd5e 100644 (file)
@@ -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++;