Fix potential crash if an engine reports an invalid currmove

Could cause an ArrayIndexOutOfBoundsException:
  at org.petero.droidfish.gamelogic.Position.getPiece (Position.java:153)
  at org.petero.droidfish.gamelogic.MoveGen.pseudoLegalMoves (MoveGen.java:109)
  at org.petero.droidfish.gamelogic.MoveGen.legalMoves (MoveGen.java:32)
  at org.petero.droidfish.gamelogic.TextIO.moveToString (TextIO.java:429)
  at org.petero.droidfish.gamelogic.TextIO.moveToString (TextIO.java:339)
  at org.petero.droidfish.gamelogic.DroidChessController$SearchListener.notifyCurrMove (DroidChessController.java:826)
This commit is contained in:
Peter Osterlund 2020-05-18 21:50:36 +02:00
parent 06375cbf1b
commit 8fdfdede44

View File

@ -838,8 +838,11 @@ public class DroidChessController {
@Override @Override
public void notifyCurrMove(int id, Position pos, Move m, int moveNr) { public void notifyCurrMove(int id, Position pos, Move m, int moveNr) {
Position tmpPos = new Position(pos);
if (!TextIO.isValid(tmpPos, m))
m = new Move(0, 0, 0);
currMove = m; currMove = m;
currMoveStr = TextIO.moveToString(pos, m, false, localPt()); currMoveStr = TextIO.moveToString(tmpPos, m, false, localPt());
currMoveNr = moveNr; currMoveNr = moveNr;
setSearchInfo(id); setSearchInfo(id);
} }