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

 
 

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

Submitted by:  Yann Dirson <ydirson>
Submitted on:  Sun 29 Sep 2013 10:14:44 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project Administrator

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup