xiaoyeli / superlu

Supernodal sparse direct solver. https://portal.nersc.gov/project/sparse/superlu/
Other
280 stars 96 forks source link

Fix usage of uninitialized variable `value` #128

Closed alugowski closed 11 months ago

alugowski commented 11 months ago

Fixes a usage of uninitialized variable value in [cdsz]langs.c if the abort conditions are triggered. Yes this isn't a true usage since ABORT will call exit() but it still causes a compiler warning in some cases.

This pops up whenever SciPy is compiled with LLVM, which happens to be configured to emit this warning:

[504/1606] Compiling C object scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_clangs.c.o
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/clangs.c:104:16: warning: variable 'value' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    } else if (strncmp(norm, "I", 1)==0) {
               ^~~~~~~~~~~~~~~~~~~~~~~~
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/clangs.c:126:13: note: uninitialized use occurs here
    return (value);
            ^~~~~
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/clangs.c:104:12: note: remove the 'if' if its condition is always true
    } else if (strncmp(norm, "I", 1)==0) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/clangs.c:78:18: note: initialize the variable 'value' to silence this warning
    float   value, sum;
                 ^
                  = 0.0
1 warning generated.

and of course 3 more copies, one each for the other 3 files.

alugowski commented 11 months ago

Here is one example of a SciPy CI build showing this warning: https://github.com/scipy/scipy/actions/runs/6829934632/job/18577020364#step:10:746