pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
305 stars 110 forks source link

warning: variable 'status' is used uninitialized whenever 'if' condition is false #201

Closed yurivict closed 1 year ago

yurivict commented 1 year ago

clang-14 prints many warnings that look damaging:

util.c:239:7: warning: variable 'status' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
                if (ret < 0) {
                    ^~~~~~~
util.c:253:20: note: uninitialized use occurs here
        ret = WEXITSTATUS(status);
                          ^~~~~~
/usr/include/sys/wait.h:61:32: note: expanded from macro 'WEXITSTATUS'
#define WEXITSTATUS(x)  (_W_INT(x) >> 8)
                                ^
/usr/include/sys/wait.h:52:20: note: expanded from macro '_W_INT'
#define _W_INT(i)       (i)
                         ^
util.c:239:3: note: remove the 'if' if its condition is always true
                if (ret < 0) {
                ^~~~~~~~~~~~~
util.c:195:12: note: initialize the variable 'status' to silence this warning
        int status;
                  ^
                   = 0
michaelolbrich commented 1 year ago

It's a false positive because ret is always -1 here. But clang doesn't know that. We can simplify the code to avoid this warning.