From 8b951bc047358ea202f4bdd419a795941bc163ff Mon Sep 17 00:00:00 2001 From: Rangi Date: Mon, 13 Jul 2026 21:31:03 -0400 Subject: [PATCH] Fix a flaky/random-seed `rgbgfx_test` test failure Commit 21eaa2d2ccb1f5b080b121dc63643ae4fa34543a missed some intentional unsigned underflow that is needed to set `nbTilesInBank`. Without it, some of the randomly-seeded RGBGFX tests, such as `./rgbgfx_test seed8.bin -b 207 -N 54,256`, can fail with "Color mismatch after round-tripping" errors. --- src/gfx/reverse.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; } } }