]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgxget: Fix clang warning
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 29 Jul 2025 16:17:13 +0000 (16:17 +0000)
committerKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 1 Aug 2025 09:02:21 +0000 (14:32 +0530)
Fix the following clang warning by explicitily initializing disk_cg to
NULL.

tools/cgxget.c:903:6: warning: variable 'disk_cg' is used uninitialized
whenever 'if' condition is true [-Wsometimes-uninitialized]
  903 |         if (!cg || !(*cg)) {
      |             ^~~~~~~~~~~~~
tools/cgxget.c:940:6: note: uninitialized use occurs here
  940 |         if (disk_cg)
      |             ^~~~~~~
tools/cgxget.c:903:2: note: remove the 'if' if its condition is always
false
  903 |         if (!cg || !(*cg)) {
      |         ^~~~~~~~~~~~~~~~~~~~
  904 |                 ret = ECGINVAL;
      |                 ~~~~~~~~~~~~~~~
  905 |                 goto out;
      |                 ~~~~~~~~~
  906 |         }
      |         ~

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

index ef69a8a2223e0a50eb8e29d9203a79e67d1fff3c..4192de59a6f77d5bbafa053eea87210d76836810 100644 (file)
@@ -897,7 +897,7 @@ err:
 #ifdef LIBCG_LIB
 int cgroup_cgxget(struct cgroup **cg, enum cg_version_t version, bool ignore_unmappable)
 {
-       struct cgroup *disk_cg, *out_cg;
+       struct cgroup *disk_cg = NULL, *out_cg;
        int ret;
 
        if (!cg || !(*cg)) {