diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index 5d9501c1..b0a814d7 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -320,9 +320,11 @@ void reverse() { ); } } else { - if (uint8_t tileID = (*tilemap)[index]; - tileID >= nbTilesInBank[bank] + options.baseTileIDs[bank]) { - nbTilesInBank[bank] = tileID - options.baseTileIDs[bank] + 1; + // The unsigned underflow for `tileOfs` is intentional, since a nonzero + // base tile ID may overflow and continue with IDs from 0. + if (uint8_t tileOfs = (*tilemap)[index] - options.baseTileIDs[bank]; + tileOfs >= nbTilesInBank[bank]) { + nbTilesInBank[bank] = tileOfs + 1; } } }