Re: [Bug] Division by zero in rscorecompare (gnuchess 6.2.9)

Antonio Ceballos <[email protected]> Mon, 13 Apr 2026 00:05:36 +0200
Newsgroups gmane.comp.gnu.chess.bugs
Message-ID <CAO7R9g9OGUPNgLhETbp=CLTd7w5b5himMsg6F1WQQ3WcB3BC_g@mail.gmail.com>
--0000000000008794aa064f4a91b3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Dear GNU Chess user,

Thank you very much for your reports. I will look into this as soon as
possible. Please note that the
last version of the package is 6.3.0, although I am not sure it will make a
difference as far as your
bug reports are concerned.

Best regards,
Antonio Ceballos


On Sun, Apr 12, 2026 at 4:19=E2=80=AFPM =E6=AD=A6=E6=B1=89=E7=90=86=E5=B7=
=A5=E5=A4=A7=E5=AD=A6-=E5=91=A8=E8=B1=AA <[email protected]> wrote:

> Dear GNU Chess maintainers,
> I found a division by zero issue in version 6.2.9.
>
> File: src/frontend/players.cc
> Function: rscorecompare
>
> The function calculates score as:
> ascore =3D (a->wins + (a->draws / 2)) / (a->wins + a->draws + a->losses);
>
> If a player has no games (wins =3D draws =3D losses =3D 0), the denominat=
or is
> 0, causing division by zero.
>
> Suggested fix:
>
> static int rscorecompare(const void *aa, const void *bb)
> {
>     const playerentry *a =3D (const playerentry *)aa;
>     const playerentry *b =3D (const playerentry *)bb;
>     float ascore, bscore;
>     int a_total =3D a->wins + a->draws + a->losses;
>     int b_total =3D b->wins + b->draws + b->losses;
>     if (a_total =3D=3D 0) ascore =3D 0.0f;
>     else ascore =3D (a->wins + (a->draws / 2.0f)) / a_total;
>     if (b_total =3D=3D 0) bscore =3D 0.0f;
>     else bscore =3D (b->wins + (b->draws / 2.0f)) / b_total;
>     if (ascore > bscore) return -1;
>     else if (bscore > ascore) return 1;
>     else return 0;
> }
>
> Please let me know if you need any more information.
>
> Best regards
>
>

--0000000000008794aa064f4a91b3
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-size:small">Dea=
r GNU Chess user,</div><div class=3D"gmail_default" style=3D"font-size:smal=
l"><br></div><div class=3D"gmail_default" style=3D"font-size:small">Thank y=
ou very much for your reports. I will look into this as soon as possible. P=
lease note that the</div><div class=3D"gmail_default" style=3D"font-size:sm=
all">last version=C2=A0of the package is 6.3.0, although I am not sure it w=
ill make a difference as far as your=C2=A0</div><div class=3D"gmail_default=
" style=3D"font-size:small">bug reports are=C2=A0concerned.</div><div class=
=3D"gmail_default" style=3D"font-size:small"><br></div><div class=3D"gmail_=
default" style=3D"font-size:small">Best regards,</div><div class=3D"gmail_d=
efault" style=3D"font-size:small">Antonio Ceballos</div><div class=3D"gmail=
_default" style=3D"font-size:small"><br></div></div><br><div class=3D"gmail=
_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sun,=
 Apr 12, 2026 at 4:19=E2=80=AFPM =E6=AD=A6=E6=B1=89=E7=90=86=E5=B7=A5=E5=A4=
=A7=E5=AD=A6-=E5=91=A8=E8=B1=AA &lt;<a href=3D"mailto:[email protected]">h=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex"><div style=3D"line-height:1.7;color:rgb(0,0,0);font-size:1=
4px;font-family:Arial"><div><div style=3D"margin:0px">Dear GNU Chess mainta=
iners,
</div><div style=3D"margin:0px">I found a division by zero issue in version=
 6.2.9.
</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">File: s=
rc/frontend/players.cc
</div><div style=3D"margin:0px">Function: rscorecompare
</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">The fun=
ction calculates score as:
</div><div style=3D"margin:0px">ascore =3D (a-&gt;wins + (a-&gt;draws / 2))=
 / (a-&gt;wins + a-&gt;draws + a-&gt;losses);
</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">If a pl=
ayer has no games (wins =3D draws =3D losses =3D 0), the denominator is 0, =
causing division by zero.
</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">Suggest=
ed fix:</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">=
static int rscorecompare(const void *aa, const void *bb)
</div><div style=3D"margin:0px">{
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 const playerentry *a =3D (con=
st playerentry *)aa;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 const playerentry *b =3D (con=
st playerentry *)bb;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 float ascore, bscore;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 int a_total =3D a-&gt;wins + =
a-&gt;draws + a-&gt;losses;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 int b_total =3D b-&gt;wins + =
b-&gt;draws + b-&gt;losses;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 if (a_total =3D=3D 0) ascore =
=3D 0.0f;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 else ascore =3D (a-&gt;wins +=
 (a-&gt;draws / 2.0f)) / a_total;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 if (b_total =3D=3D 0) bscore =
=3D 0.0f;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 else bscore =3D (b-&gt;wins +=
 (b-&gt;draws / 2.0f)) / b_total;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 if (ascore &gt; bscore) retur=
n -1;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 else if (bscore &gt; ascore) =
return 1;
</div><div style=3D"margin:0px">=C2=A0 =C2=A0 else return 0;
</div><div style=3D"margin:0px">}
</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">Please =
let me know if you need any more information.
</div><div style=3D"margin:0px"><br></div><div style=3D"margin:0px">Best re=
gards</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">   =20
</div><div style=3D"margin:0px">   =20
</div><div style=3D"margin:0px">   =20
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><div style=3D"margin:0px">
</div><br></div></div></blockquote></div>

--0000000000008794aa064f4a91b3--