From 07f59690057c73c24d0856635145798b9dbab805 Mon Sep 17 00:00:00 2001 From: Rangi Date: Tue, 14 Jul 2026 11:27:41 -0400 Subject: [PATCH] Consistency check the palette map, not just the attribute map --- src/gfx/reverse.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index 79381aa9..3771fe1e 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -419,6 +419,27 @@ void reverse() { mapSize ); } + + for (size_t index = 0; index < mapSize; ++index) { + size_t tx = index % width, ty = index / width; + uint8_t palID = (*palmap)[index]; + + // The unsigned underflow for `palOfs` is intentional, since a nonzero + // base palette ID may overflow and continue with IDs from 0. + if (uint8_t palOfs = (palID - options.basePalID) & 0b111; palOfs >= palettes.size()) { + error( + "Palette map references palette #%" PRIu8 + " at (%zu, %zu), but there are only %zu palette%s", + palID, + tx, + ty, + palettes.size(), + palettes.size() == 1 ? "" : "s" + ); + } + } + + requireZeroErrors(); } verbosePrint(VERB_NOTICE, "Writing image...\n");