ibm-capi / pslse

Power Service Layer Simulation Engine
28 stars 22 forks source link

Fix for clang "use of uninitialized variables" error. #109

Closed jonmayergoogle closed 3 years ago

jonmayergoogle commented 6 years ago

Clang/LLVM is paranoid about potential use of uninitialized variables, and flags this code with errors such as:

pslse/cmd.c:1927:11: error: variable 'this_itag' is used uninitialized whenever 'while' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized]
                        while (need_a_tag == 1)  {
                               ^~~~~~~~~~~~~~~
pslse/cmd.c:1957:18: note: uninitialized use occurs here
                        event->itag = this_itag;
                                      ^~~~~~~~~
pslse/cmd.c:1927:11: note: remove the condition if it is always true
                        while (need_a_tag == 1)  {
                               ^~~~~~~~~~~~~~~
                               1
pslse/pslse/cmd.c:1813:20: note: initialize the variable 'this_itag' to silence this warning
        uint32_t this_itag, done_it;
                          ^
                           = 0

This pull request fixes this issue by changing some while loops into do-while loops.

jonmayergoogle commented 6 years ago

Though, on reflection, it looks like the "} while (need_a_tag == 1)" code will never be executed, since the code is structured such that all codepaths lead to a "break" statement.

I think my changes are still an improvement, but maybe some further cleanup is warranted.

bmesnet commented 3 years ago

Ok with the change and the comments