EditBoard: fix error handling in piece setting.
authorYann Dirson <ydirson@free.fr>
Sun, 16 Feb 2014 13:51:28 +0000 (14:51 +0100)
committerYann Dirson <ydirson@free.fr>
Sun, 16 Feb 2014 15:11:18 +0000 (16:11 +0100)
On invalid piece name, the code was anyway destroying any piece in the
target location, and the whole logic was diluted.

NEWS
gnushogi/cursesdsp.c
gnushogi/rawdsp.c

diff --git a/NEWS b/NEWS
index 0fda42d..d5bc3b2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Changes in version 1.4.2 (unreleased):
 
 * XShogi is no longer included in the GNU Shogi source, it is
   available as a separate source archive.
+* Fix clobbering of board on invalid input when editing board.
 * Fixed Curses mode display:
   - reversed column number for MiniShogi
   - clock position for MiniShogi
index 16125a0..2fa6d4c 100644 (file)
@@ -531,13 +531,12 @@ Curses_EditBoard(void)
             continue;
 
         sq = locn(r, c);
-        color[sq] = a;
-        board[sq] = no_piece;
 
         for (i = NO_PIECES; i > no_piece; i--)
         {
             if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
             {
+                color[sq] = a;
                 if (s[3] == '+')
                     board[sq] = promoted[i];
                 else
@@ -548,10 +547,6 @@ Curses_EditBoard(void)
             }
         }
 
-
-        if (found == 0)
-            color[sq] = neutral;
-
         DrawPiece(sq);
     }
 
index 2c4d185..0ca5c5a 100644 (file)
@@ -396,13 +396,12 @@ Raw_EditBoard(void)
         }
 
         sq = locn(r, c);
-        color[sq] = a;
-        board[sq] = no_piece;
 
         for (i = no_piece; i <= king; i++)
         {
             if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
             {
+                color[sq] = a;
                 if (s[3] == '+')
                     board[sq] = promoted[i];
                 else
@@ -412,9 +411,6 @@ Raw_EditBoard(void)
                 break;
             }
         }
-
-        if (found == 0)
-            color[sq] = neutral;
     }
 
     for (sq = 0; sq < NO_SQUARES; sq++)