diff --git a/xwords4/common/model.c b/xwords4/common/model.c index f6fc9fb49..e692c8545 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -90,7 +90,9 @@ model_make( MPFORMAL DictionaryCtxt* dict, XP_U16 nRows ) { ModelCtxt* result; - XP_U16 size = sizeof(*result) + TILES_SIZE(result, nCols); + XP_U16 size; + XP_ASSERT( nCols == nRows && nCols <= MAX_COLS ); + size = sizeof(*result) + TILES_SIZE(result, nCols); result = (ModelCtxt*)XP_MALLOC( mpool, size ); if ( result != NULL ) { XP_MEMSET( result, 0, sizeof(*result) ); @@ -700,15 +702,11 @@ setModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row, CellTile tile ) static CellTile getModelTileRaw( const ModelCtxt* model, XP_U16 col, XP_U16 row ) { - CellTile tile; XP_U16 nCols = model->nCols; XP_ASSERT( model->nRows == nCols ); - if ( col < nCols && row < nCols ) { - tile = model->tiles[(row*nCols) + col]; - } else { - tile = TILE_EMPTY_BIT; - } - return tile; + XP_ASSERT( col < nCols ); + XP_ASSERT( row < nCols ); + return model->tiles[(row*nCols) + col]; } /* getModelTileRaw */ static void diff --git a/xwords4/common/mscore.c b/xwords4/common/mscore.c index 4077f613c..1131b984a 100644 --- a/xwords4/common/mscore.c +++ b/xwords4/common/mscore.c @@ -318,10 +318,11 @@ static XP_Bool modelIsEmptyAt( const ModelCtxt* model, XP_U16 col, XP_U16 row ) { Tile tile; - XP_Bool found; - - found = model_getTile( model, col, row, XP_FALSE, -1, &tile, - NULL, NULL, NULL ); + XP_U16 nCols = model_numCols( model ); + XP_Bool found = col < nCols + && row < nCols + && model_getTile( model, col, row, XP_FALSE, -1, &tile, + NULL, NULL, NULL ); return !found; } /* modelIsEmptyAt */ @@ -722,11 +723,12 @@ find_end( const ModelCtxt* model, XP_U16 col, XP_U16 row, XP_Bool isHorizontal ) { XP_U16* incr = isHorizontal? &col: &row; - XP_U16 limit = isHorizontal? MAX_COLS-1:MAX_ROWS-1; + XP_U16 nCols = model_numCols( model ); + XP_U16 limit = nCols - 1; XP_U16 lastGood = *incr; - XP_ASSERT( col < MAX_COLS ); - XP_ASSERT( row < MAX_ROWS ); + XP_ASSERT( col < nCols ); + XP_ASSERT( row < nCols ); for ( ; ; ) { XP_ASSERT( *incr <= limit );