From bc00a04873d52492a103a86219a3bfc875196360 Mon Sep 17 00:00:00 2001 From: ehouse Date: Fri, 14 May 2004 08:55:13 +0000 Subject: [PATCH] fix infinite loop when attempting to undo tile assignment. The ideal fix would allow the undo, but this is much less risky. --- xwords4/common/model.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xwords4/common/model.c b/xwords4/common/model.c index e5f472443..cdbfb6de3 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -534,8 +534,13 @@ model_undoLatestMoves( ModelCtxt* model, PoolContext* pool, XP_Bool success = XP_TRUE; XP_S16 moveSought = *moveNumP; XP_U16 nMovesUndone; + XP_U16 nStackEntries; - if ( stack_getNEntries( stack ) < nMovesSought ) { + nStackEntries = stack_getNEntries( stack ); + if ( nStackEntries < nMovesSought ) { + return XP_FALSE; + } else if ( nStackEntries <= model->nPlayers ) { + util_userError( model->vol.util, ERR_CANT_UNDO_TILEASSIGN ); return XP_FALSE; } @@ -578,6 +583,7 @@ model_undoLatestMoves( ModelCtxt* model, PoolContext* pool, /* nothing to do, since nothing happened */ } else { + XP_ASSERT( entry.moveType == ASSIGN_TYPE ); success = XP_FALSE; break; } @@ -616,6 +622,8 @@ model_undoLatestMoves( ModelCtxt* model, PoolContext* pool, notifyBoardListeners( model, entry.playerNum, col, row, XP_FALSE ); } break; + } else if ( entry.moveType == ASSIGN_TYPE ) { + break; } }