]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix build warnings
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 20 Apr 2022 15:09:33 +0000 (09:09 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 20 Apr 2022 15:09:56 +0000 (09:09 -0600)
Fix the use before initialization build warnings:

api.c: In function ‘cgroup_populate_controllers.constprop’:
api.c:1386:5: warning: ‘buf’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1386 |  if (buf)
      |     ^
api.c: In function ‘cgroup_populate_mount_points.constprop’:
api.c:1461:5: warning: ‘temp_ent’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1461 |  if (temp_ent)
      |     ^

this patch, initializes them to NULL.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 1c4eaa33a10dcfdf4c9cba76fa01a1562d2dfe47..ca71ef29cdbc89aec37d5916efc2c48a6e86c120 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1333,9 +1333,9 @@ static int cgroup_populate_controllers(char *controllers[CG_CONTROLLER_MAX])
        int hierarchy, num_cgroups, enabled;
        char subsys_name[FILENAME_MAX];
        FILE *proc_cgroup;
+       char *buf = NULL;
        int ret = 0;
        int i, err;
-       char *buf;
 
        proc_cgroup = fopen("/proc/cgroups", "re");
        if (!proc_cgroup) {
@@ -1404,7 +1404,7 @@ err:
 static int cgroup_populate_mount_points(char *controllers[CG_CONTROLLER_MAX])
 {
        char mntent_buffer[4 * FILENAME_MAX];
-       struct mntent *temp_ent, *ent;
+       struct mntent *ent, *temp_ent = NULL;
        int found_mnt = 0;
        FILE *proc_mount;
        int ret = 0;