do away with need to accept out-of-bounds values in getTileRaw().

This commit is contained in:
Eric House 2011-11-23 18:25:12 -08:00
parent 795b86e569
commit 2bfe120014
2 changed files with 15 additions and 15 deletions

View file

@ -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

View file

@ -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 );