xiw/stack

Variable is used while uninitialized

hughescr opened this issue · 4 comments

This is probably not so good, in a tool which is supposed to check for exactly this kind of issue. The compiler catches it as a warning:

lglib.c:6896:7: warning: variable 'res' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (abs (lgl->opts->bias.val) <= 1) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lglib.c:6967:10: note: uninitialized use occurs here
return res;
^~~
lglib.c:6896:3: note: remove the 'if' if its condition is always false
if (abs (lgl->opts->bias.val) <= 1) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lglib.c:6886:16: note: initialize the variable 'res' to silence this warning
int lidx, res, l4, r4, b4, l10, r10, b10, m, oldbias;
^
= 0

xiw commented

We turned off this intentionally since compilers are doing a good job about uninitialized variables. You can turn this on by changing STACK's script.

Not sure what you mean by "we removed this". It's in the code now -- uninitialized variable warning. The warning can be removed easily, and the code corrected, by initializing "res" in the declaration line as suggested by clang, or if you want to leave it uninitalized by bracketing the offending code with a #pragma that turns off that warning for that particular occurrence. Either way, leaving the warnings in the code is likely to make people question your attention to sloppy code in a code-sloppiness detection tool.

xiw commented

Oops I misread your report. This is an issue in the Lingeling solver, which you should report upstream. Thanks.

xiw commented

Looks like the return value res is not used by its callee at all. I'm closing this issue.