From 93a621c65c410c87dd24bb1a199caca12c4c6d31 Mon Sep 17 00:00:00 2001 From: ehouse Date: Wed, 12 Mar 2008 12:21:23 +0000 Subject: [PATCH] fix crash: check that tile exists before removing --- common/model.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/common/model.c b/common/model.c index 81ede84f5..70d271059 100644 --- a/common/model.c +++ b/common/model.c @@ -1027,29 +1027,30 @@ model_moveBoardToTray( ModelCtxt* model, XP_S16 turn, } } - /* may be legal to fail to find, but we'd better return now! */ - XP_ASSERT( index < player->nPending ); + /* if we're called from putBackOtherPlayersTiles there may be nothing + here */ + if ( index < player->nPending ) { + decrPendingTileCountAt( model, col, row ); + notifyBoardListeners( model, turn, col, row, XP_FALSE ); - decrPendingTileCountAt( model, col, row ); - notifyBoardListeners( model, turn, col, row, XP_FALSE ); + tile = pt->tile; + if ( (tile & TILE_BLANK_BIT) != 0 ) { + tile = dict_getBlankTile( model->vol.dict ); + } - tile = pt->tile; - if ( (tile & TILE_BLANK_BIT) != 0 ) { - tile = dict_getBlankTile( model->vol.dict ); + model_addPlayerTile( model, turn, trayOffset, tile ); + + --player->nPending; + for ( i = index; i < player->nPending; ++i ) { + player->pendingTiles[i] = player->pendingTiles[i+1]; + } + + if ( player->nPending == 0 ) { + invalLastMove( model ); + } + + invalidateScore( model, turn ); } - - model_addPlayerTile( model, turn, trayOffset, tile ); - - --player->nPending; - for ( i = index; i < player->nPending; ++i ) { - player->pendingTiles[i] = player->pendingTiles[i+1]; - } - - if ( player->nPending == 0 ) { - invalLastMove( model ); - } - - invalidateScore( model, turn ); } /* model_moveBoardToTray */ void