miguel-ambrona / D3-Chess

Chess Unwinnability Analyzer is an implementation of a decision procedure for checking whether there exists a sequence of legal moves that allows a certain player to checkmate their opponent in a given chess position.
https://chasolver.org
GNU General Public License v3.0
51 stars 8 forks source link

Uninitialized values in semistatic.cpp #6

Closed vonaka closed 3 years ago

vonaka commented 3 years ago

I believe that in function SemiStatic::System::init() presquares[j] can be not yet initialized at the moment of execution of line 36. And it looks like valgrind agrees with me:

Chess Unwinnability Analyzer (CHA) version 2.2
==9138== Conditional jump or move depends on uninitialised value(s)
==9138==    at 0x169772: SemiStatic::System::init() (semistatic.cpp:36)
==9138==    by 0x10EF76: main (main.cpp:31)
==9138==  Uninitialised value was created by a stack allocation
==9138==    at 0x16A720: SemiStatic::init() (semistatic.cpp:330)
==9138== 
miguel-ambrona commented 3 years ago

Hi vonaka, thank you so much for your feedback! I understand your point. It is a good idea to include your proposed fix, which leads to a functionally equivalent program, but which avoids the valgrind memory warning. (Note that values that were not initialized in presquares were never read by the program.)