bugGNU shogi - Bugs: bug #40143, search.c::SelectMove can use...

 
 

bug #40143: search.c::SelectMove can use "blockable" uninitialized

Submitter:  Yann Dirson <ydirson>
Submitted:  Sun 29 Sep 2013 10:14:44 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 05 Mar 2014 08:38:34 AM UTC, comment #1: 

This seems to be a 'false alarm'. 'blockable' is only used in MakeList in the statement

if(!InCheck || blockable)

where InCheck is a copy of in_check due to

if(in_check >= 0) InCheck = in_check;

whether in_check is true or false (the only two possibilities), as both are >= 0. So if in_check is false, leaving blockable uninitialized, the !InCheck operand of || will be true, and bockable will not be tested.

This also makes sense: the purpose is to determine if there can be legal drop moves. This is certainly the case when you are not in check, but when in check, contact checks can never be evaded by dropping something. So only in that case it becomes relevant whether the check was (in principle) blockable or not.

hgm

Anonymous
Sun 29 Sep 2013 10:14:44 PM UTC, original submission:  

CLang reports:

/«PKGBUILDDIR»/./gnushogi/search.c:248:16: warning: variable 'blockable' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]
    in_check = (board[sqking] == king)
               ^~~~~~~~~~~~~~~~~~~~~~~
/«PKGBUILDDIR»/./gnushogi/search.c:252:33: note: uninitialized use occurs here
    MoveList(side, 1, in_check, blockable);
                                ^~~~~~~~~
/«PKGBUILDDIR»/./gnushogi/search.c:248:16: note: remove the '?:' if its condition is always true
    in_check = (board[sqking] == king)
               ^~~~~~~~~~~~~~~~~~~~~~~
/«PKGBUILDDIR»/./gnushogi/search.c:151:38: note: initialize the variable 'blockable' to silence this warning
    short sqking, in_check, blockable;
                                     ^
                                      = 0
1 warning generated.


Looks like blockable should be initialized first, but what MoveList() does with the value
is not clear to me - in some cases where it was not initialized in SelectMove(), MoveList()
will call SqAttacked() itself (with different parameters !?) and in some cases not...

The strange use of integers as bools, and mix of in_check and InCheck all help to obuscate things...

Yann Dirson <ydirson>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ydirson (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code