Fix some uninitialized variable bugs
[xboard.git] / backend.c
index 1c684ad..e50e869 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -8908,6 +8908,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
       /* For variants we don't have   */       && gameInfo.variant != VariantBerolina
       /* correct rules for, we cannot */       && gameInfo.variant != VariantCylinder
       /* enforce legality on our own! */       && gameInfo.variant != VariantUnknown
+                                               && gameInfo.variant != VariantGreat
                                                && gameInfo.variant != VariantFairy    ) return;
       if(piece < EmptySquare) {
         pieceDefs = TRUE;
@@ -12857,7 +12858,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList)
        if (!err) numPGNTags++;
 
         /* [HGM] PGNvariant: automatically switch to variant given in PGN tag */
-        if(gameInfo.variant != oldVariant) {
+        if(gameInfo.variant != oldVariant && (gameInfo.variant != VariantNormal || gameInfo.variantName == NULL || *gameInfo.variantName == NULLCHAR)) {
             startedFromPositionFile = FALSE; /* [HGM] loadPos: variant switch likely makes position invalid */
            ResetFrontEnd(); // [HGM] might need other bitmaps. Cannot use Reset() because it clears gameInfo :-(
            InitPosition(TRUE);
@@ -15078,6 +15079,8 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y)
 
     switch (selection) {
       case ClearBoard:
+       fromX = fromY = killX = killY = -1; // [HGM] abort any move entry in progress
+       MarkTargetSquares(1);
        CopyBoard(currentBoard, boards[0]);
        CopyBoard(menuBoard, initialPosition);
        if (gameMode == IcsExamining && ics_type == ICS_FICS) {
@@ -17868,7 +17871,7 @@ PositionToFEN (int move, char *overrideCastling, int moveCounts)
             q = (boards[move][CASTLING][1] == BOARD_LEFT &&
                  boards[move][CASTLING][2] != NoRights  );
             if(handW) { // for S-Chess with pieces in hand, list virgin pieces between K and Q
-                for(i=BOARD_RGHT-1-k; i>=BOARD_LEFT+q && j; i--)
+                for(i=BOARD_RGHT-1-k; i>=BOARD_LEFT+q; i--)
                     if((boards[move][0][i] != WhiteKing || k+q == 0) &&
                         boards[move][VIRGIN][i] & VIRGIN_W) *p++ = i + AAA + 'A' - 'a';
             }
@@ -17879,7 +17882,7 @@ PositionToFEN (int move, char *overrideCastling, int moveCounts)
             q = (boards[move][CASTLING][4] == BOARD_LEFT &&
                  boards[move][CASTLING][5] != NoRights  );
             if(handB) {
-                for(i=BOARD_RGHT-1-k; i>=BOARD_LEFT+q && j; i--)
+                for(i=BOARD_RGHT-1-k; i>=BOARD_LEFT+q; i--)
                     if((boards[move][BOARD_HEIGHT-1][i] != BlackKing || k+q == 0) &&
                         boards[move][VIRGIN][i] & VIRGIN_B) *p++ = i + AAA;
             }