Re: [PATCH] Fix loading EPD files
Antonio Ceballos <[email protected]> Sun, 1 Jun 2025 14:14:16 +0200
| Newsgroups | gmane.comp.gnu.chess.bugs |
|---|---|
| Message-ID | <CAO7R9g_=zULO1a+G+ecTjTx7Uk8qWgg2gmhjtobeTE_2ku_vvw@mail.gmail.com> |
--000000000000c41c2d0636819654 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Rudolf, Thanks for spotting this bug, and for the detailed description of the steps you followed. I have reproduced it in the pre-release 6.3.0-pre2. It seems that it was introduced in version 6.2.9. Your patch looks good and it fixes the problem indeed! Thanks for it! I will include it in the upcoming version 6.3.0. Cheers, Antonio Ceballos On Fri, May 30, 2025 at 3:36=E2=80=AFAM Rudolf Polzer <[email protected]>= wrote: > Hi, > > I am currently playing around with the GNU Chess engine and patching > around in it for fun, and while doing so, found some minor bugs in the > source. > > As I am new to the project and not yet clear about e.g. the coding > style, let me start with a simple and trivial fix: currently one > cannot correctly load EPD files; the following happens: > > ``` > $ cat t > rnbqkb1r/pppppppp/5n2/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - bm 1; id 1; > $ src/gnuchess --easy > GNU Chess > Can't open file "(null)": Bad address - using defaults > White (1) : post > White (1) : depth 5 > Search to a depth of 5. > White (1) : load t > > : Best move =3D 1 > > white KQkq > > r n b q k b . r > p p p p p p p p > . . . . . n . . > . . . . . . . . > . . . . P . . . > . . . . . . . . > P P P P . P P P > R N B Q K B N R > > Error loading EPD file 't'. > White (1) : f4 > 1. f4 > > black KQkq f3 > > r n b q k b . r > p p p p p p p p > . . . . . n . . > . . . . . . . . > . . . . P P . . > . . . . . . . . > P P P P . . P P > R N B Q K B N R > > Thinking... > 1 -6 0 2 a5 > White (1) : 1 -1 0 4 b5 > 1 +41 0 8 d5 > 1 +43 0 21 Nc6 > 2 +9 0 47 Nc6 Nc3 > 3 +43 0 155 Nc6 Nc3 Nf6 > 4 +9 0 788 Nc6 Nf3 Nf6 Nc3 > 5 +37 0 2920 Nc6 Nf3 Nf6 Nc3 d5 > 5 +37 1 5024 Nc6 Nf3 Nf6 Nc3 d5 > > white KQkq > > r . b q k b . r > p p p p p p p p > . . n . . n . . > . . . . . . . . > . . . . P P . . > . . . . . . . . > P P P P . . P P > R N B Q K B N R > > > My move is : Nc6 > ``` > > So it's not taking the free pawn on e4. > > If I instead don't load, but play the move from scratch, it reliably will= . > > A clue is the "Error loading EPD file 't'." message, and indeed, the > code has a bug there - it uses strlen on a buffer that's initialized > empty (thus is always 0) when clearly sizeof was intended, and on > failure it seems the board is loaded into some variables but not into > others. After this patch: > > ``` > From 7655b2c6bb98d1bfec5852124d05adec34df353d Mon Sep 17 00:00:00 2001 > From: Rudolf Polzer <[email protected]> > Date: Thu, 29 May 2025 06:46:39 -0400 > Subject: [PATCH 1/1] Fix loading EPD files. > > --- > src/frontend/cmd.cc | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/frontend/cmd.cc b/src/frontend/cmd.cc > index f038e62..dacbd66 100644 > --- a/src/frontend/cmd.cc > +++ b/src/frontend/cmd.cc > @@ -394,7 +394,7 @@ void cmd_load(void) > printf (_("Board is wrong!\n")); > } else { > /* Read EPD file and send contents to engine */ > - if (build_setboard_cmd_from_epd_file(data, epd_filename, > strlen(data))) { > + if (build_setboard_cmd_from_epd_file(data, epd_filename, > sizeof(data))) { > SetDataToEngine( data ); > SetAutoGo( true ); > } else { > -- > 2.39.5 > ``` > > it's taking the pawn just fine: > > ``` > $ src/gnuchess --easy > GNU Chess > Can't open file "(null)": Bad address - using defaults > White (1) : post > White (1) : depth 5 > Search to a depth of 5. > White (1) : load t > > : Best move =3D 1 > > white KQkq > > r n b q k b . r > p p p p p p p p > . . . . . n . . > . . . . . . . . > . . . . P . . . > . . . . . . . . > P P P P . P P P > R N B Q K B N R > > White (1) : f4 > 1. f4 > > black KQkq f3 > > r n b q k b . r > p p p p p p p p > . . . . . n . . > . . . . . . . . > . . . . P P . . > . . . . . . . . > P P P P . . P P > R N B Q K B N R > > Thinking... > Thinking... > 1 +168 0 2 Nxe4 > Black (1) : 2 +130 0 130 Nxe4 Nc3 > 3 +132 0 547 Nxe4 Nc3 d5 Nxe4 dxe4 > 4 +117 0 1471 Nxe4 d3 Nc5 Nc3 > 5 +135 1 5352 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4 > 5 +135 1 7197 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4 > > white KQkq > > r n b q k b . r > p p p p p p p p > . . . . . . . . > . . . . . . . . > . . . . n P . . > . . . . . . . . > P P P P . . P P > R N B Q K B N R > > > My move is : Nxe4 > ``` > > Does this patch look correct? Hope Gmail didn't ruin things - I can > try using another address if it doesn't work well with this mailing > list, but would like any commits to be associated with this primary > one if possible. > > Thank you, > > Rudolf "divVerent" Polzer > > --000000000000c41c2d0636819654 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">Hi = Rudolf,</div><div class=3D"gmail_default" style=3D"font-size:small"><br></d= iv><div class=3D"gmail_default" style=3D"font-size:small">Thanks for spotti= ng this bug, and for the detailed description of the steps you followed.</d= iv><div class=3D"gmail_default" style=3D"font-size:small">I have reproduced= it in the pre-release 6.3.0-pre2. It seems that it was introduced in=C2=A0= </div><div class=3D"gmail_default" style=3D"font-size:small">version 6.2.9.= </div><div class=3D"gmail_default" style=3D"font-size:small"><br></div><div= class=3D"gmail_default" style=3D"font-size:small">Your patch looks good an= d it fixes the problem indeed! Thanks for it! I will include it</div><div c= lass=3D"gmail_default" style=3D"font-size:small">in the upcoming version 6.= 3.0.</div><div class=3D"gmail_default" style=3D"font-size:small"><br></div>= <div class=3D"gmail_default" style=3D"font-size:small">Cheers,</div><div cl= ass=3D"gmail_default" style=3D"font-size:small">Antonio Ceballos</div><div = class=3D"gmail_default" style=3D"font-size:small"><br></div><div class=3D"g= mail_default" style=3D"font-size:small"><br></div></div><br><div class=3D"g= mail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On = Fri, May 30, 2025 at 3:36=E2=80=AFAM Rudolf Polzer <<a href=3D"mailto:di= [email protected]">[email protected]</a>> wrote:<br></div><blockquote = class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px sol= id rgb(204,204,204);padding-left:1ex">Hi,<br> <br> I am currently playing around with the GNU Chess engine and patching<br> around in it for fun, and while doing so, found some minor bugs in the<br> source.<br> <br> As I am new to the project and not yet clear about e.g. the coding<br> style, let me start with a simple and trivial fix: currently one<br> cannot correctly load EPD files; the following happens:<br> <br> ```<br> $ cat t<br> rnbqkb1r/pppppppp/5n2/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - bm 1; id 1;<br> $ src/gnuchess=C2=A0 --easy<br> GNU Chess<br> Can't open file "(null)": Bad address - using defaults<br> White (1) : post<br> White (1) : depth 5<br> Search to a depth of 5.<br> White (1) : load t<br> <br> =C2=A0: Best move =3D 1<br> <br> white=C2=A0 KQkq<br> <br> r n b q k b . r<br> p p p p p p p p<br> . . . . . n . .<br> . . . . . . . .<br> . . . . P . . .<br> . . . . . . . .<br> P P P P . P P P<br> R N B Q K B N R<br> <br> Error loading EPD file 't'.<br> White (1) : f4<br> 1. f4<br> <br> black=C2=A0 KQkq=C2=A0 f3<br> <br> r n b q k b . r<br> p p p p p p p p<br> . . . . . n . .<br> . . . . . . . .<br> . . . . P P . .<br> . . . . . . . .<br> P P P P . . P P<br> R N B Q K B N R<br> <br> Thinking...<br> 1 -6 0 2 a5<br> White (1) : 1 -1 0 4 b5<br> 1 +41 0 8 d5<br> 1 +43 0 21 Nc6<br> 2 +9 0 47 Nc6 Nc3<br> 3 +43 0 155 Nc6 Nc3 Nf6<br> 4 +9 0 788 Nc6 Nf3 Nf6 Nc3<br> 5 +37 0 2920 Nc6 Nf3 Nf6 Nc3 d5<br> 5 +37 1 5024 Nc6 Nf3 Nf6 Nc3 d5<br> <br> white=C2=A0 KQkq<br> <br> r . b q k b . r<br> p p p p p p p p<br> . . n . . n . .<br> . . . . . . . .<br> . . . . P P . .<br> . . . . . . . .<br> P P P P . . P P<br> R N B Q K B N R<br> <br> <br> My move is : Nc6<br> ```<br> <br> So it's not taking the free pawn on e4.<br> <br> If I instead don't load, but play the move from scratch, it reliably wi= ll.<br> <br> A clue is the "Error loading EPD file 't'." message, and = indeed, the<br> code has a bug there - it uses strlen on a buffer that's initialized<br= > empty (thus is always 0) when clearly sizeof was intended, and on<br> failure it seems the board is loaded into some variables but not into<br> others. After this patch:<br> <br> ```<br> From 7655b2c6bb98d1bfec5852124d05adec34df353d Mon Sep 17 00:00:00 2001<br> From: Rudolf Polzer <<a href=3D"mailto:[email protected]" target=3D"_b= lank">[email protected]</a>><br> Date: Thu, 29 May 2025 06:46:39 -0400<br> Subject: [PATCH 1/1] Fix loading EPD files.<br> <br> ---<br> =C2=A0src/frontend/cmd.cc | 2 +-<br> =C2=A01 file changed, 1 insertion(+), 1 deletion(-)<br> <br> diff --git a/src/frontend/cmd.cc b/src/frontend/cmd.cc<br> index f038e62..dacbd66 100644<br> --- a/src/frontend/cmd.cc<br> +++ b/src/frontend/cmd.cc<br> @@ -394,7 +394,7 @@ void cmd_load(void)<br> =C2=A0 =C2=A0 =C2=A0printf (_("Board is wrong!\n"));<br> =C2=A0 =C2=A0} else {<br> =C2=A0 =C2=A0 =C2=A0/* Read EPD file and send contents to engine */<br> -=C2=A0 =C2=A0 if (build_setboard_cmd_from_epd_file(data, epd_filename, str= len(data))) {<br> +=C2=A0 =C2=A0 if (build_setboard_cmd_from_epd_file(data, epd_filename, siz= eof(data))) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0SetDataToEngine( data );<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0SetAutoGo( true );<br> =C2=A0 =C2=A0 =C2=A0} else {<br> -- <br> 2.39.5<br> ```<br> <br> it's taking the pawn just fine:<br> <br> ```<br> $ src/gnuchess --easy<br> GNU Chess<br> Can't open file "(null)": Bad address - using defaults<br> White (1) : post<br> White (1) : depth 5<br> Search to a depth of 5.<br> White (1) : load t<br> <br> =C2=A0: Best move =3D 1<br> <br> white=C2=A0 KQkq<br> <br> r n b q k b . r<br> p p p p p p p p<br> . . . . . n . .<br> . . . . . . . .<br> . . . . P . . .<br> . . . . . . . .<br> P P P P . P P P<br> R N B Q K B N R<br> <br> White (1) : f4<br> 1. f4<br> <br> black=C2=A0 KQkq=C2=A0 f3<br> <br> r n b q k b . r<br> p p p p p p p p<br> . . . . . n . .<br> . . . . . . . .<br> . . . . P P . .<br> . . . . . . . .<br> P P P P . . P P<br> R N B Q K B N R<br> <br> Thinking...<br> Thinking...<br> 1 +168 0 2 Nxe4<br> Black (1) : 2 +130 0 130 Nxe4 Nc3<br> 3 +132 0 547 Nxe4 Nc3 d5 Nxe4 dxe4<br> 4 +117 0 1471 Nxe4 d3 Nc5 Nc3<br> 5 +135 1 5352 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4<br> 5 +135 1 7197 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4<br> <br> white=C2=A0 KQkq<br> <br> r n b q k b . r<br> p p p p p p p p<br> . . . . . . . .<br> . . . . . . . .<br> . . . . n P . .<br> . . . . . . . .<br> P P P P . . P P<br> R N B Q K B N R<br> <br> <br> My move is : Nxe4<br> ```<br> <br> Does this patch look correct? Hope Gmail didn't ruin things - I can<br> try using another address if it doesn't work well with this mailing<br> list, but would like any commits to be associated with this primary<br> one if possible.<br> <br> Thank you,<br> <br> Rudolf "divVerent" Polzer<br> <br> </blockquote></div> --000000000000c41c2d0636819654--