[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnubg] Bug in PositionBearoff() and PositionIndex()

From: Philippe Michel
Subject: [Bug-gnubg] Bug in PositionBearoff() and PositionIndex()
Date: Mon, 30 Apr 2012 00:00:46 +0200 (CEST)
User-agent: Alpine 2.00 (BSF 1167 2008-08-23)

I think there is something wrong (but harmless with the compilers we've used) in these functions from positionid.c.

In PositionBearoff() for instance :

    for( j = nPoints - 1, i = 0; i < nPoints; i++ )
        j += anBoard[ i ];

    fBits = 1u << j;

    for( i = 0; i < nPoints; i++ ) {
        j -= anBoard[ i ] + 1;
        fBits |= ( 1u << j );

the last "1u << j" is always 1u << (-1) which is undefined (and apparently happens to end as 1<<31) : start with nPoints - 1, count checkers on the lower nPoints then substract (checkers+1) for each of nPoints.

I don't really understand what the index thus calculated means, but setting the bit at the other end of fBits is probably not what is intended and the way it is done is unsound anyway.

The code in PositionIndex() is almost identical.

Doing one less loop with
    for( i = 0; i < nPoints - 1; i++ )
gives the same result in gnubg since apparently fBits is only used in some masking with values smaller than 2^31. I didn't look at what happens with the bearoff database building commands.

Could someone who understand this part of the code confirm that this is the right thing to do or suggest a proper fix ?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]