From 3631fab63c9149b62d3f0725066db4680fa70f25 Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Fri, 5 Dec 2025 11:21:00 -0500 Subject: [PATCH] Fix bug where an object's invalid ROMX bank of 0 could break rgblink (#1868) --- src/link/assign.cpp | 3 ++- src/link/output.cpp | 12 ++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/link/assign.cpp b/src/link/assign.cpp index 6211a6b9..41ec1e57 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -122,8 +122,9 @@ static std::optional getPlacement(Section const §ion, MemoryLocation if (location.bank < typeInfo.firstBank || location.bank >= memory[section.type].size() + typeInfo.firstBank) { fatal( - "Invalid bank for %s section: 0x%02x", + "Invalid bank for %s section \"%s\": %" PRIu32, sectionTypeInfo[section.type].name.c_str(), + section.name.c_str(), location.bank ); } diff --git a/src/link/output.cpp b/src/link/output.cpp index 6de2affb..e08eb629 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -71,9 +71,7 @@ void out_AddSection(Section const §ion) { }; uint32_t targetBank = section.bank - sectionTypeInfo[section.type].firstBank; - uint32_t minNbBanks = targetBank + 1; - - if (minNbBanks > maxNbBanks[section.type]) { + if (targetBank >= maxNbBanks[section.type]) { fatal( "Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")", section.name.c_str(), @@ -81,16 +79,14 @@ void out_AddSection(Section const §ion) { maxNbBanks[section.type] - 1 ); } - - for (uint32_t i = sections[section.type].size(); i < minNbBanks; ++i) { - sections[section.type].emplace_back(); + if (sections[section.type].size() <= targetBank) { + sections[section.type].resize(targetBank + 1); } + // Insert section while keeping the list sorted by increasing org std::deque
&bankSections = section.size ? sections[section.type][targetBank].sections : sections[section.type][targetBank].zeroLenSections; - - // Insert section while keeping the list sorted by increasing org auto pos = bankSections.begin(); while (pos != bankSections.end() && (*pos)->org < section.org) { ++pos;