Fix bug where an object's invalid ROMX bank of 0 could break rgblink (#1868)

This commit is contained in:
Rangi
2025-12-05 11:21:00 -05:00
committed by GitHub
parent 1c00123b33
commit 3631fab63c
2 changed files with 6 additions and 9 deletions

View File

@@ -122,8 +122,9 @@ static std::optional<size_t> getPlacement(Section const &section, MemoryLocation
if (location.bank < typeInfo.firstBank if (location.bank < typeInfo.firstBank
|| location.bank >= memory[section.type].size() + typeInfo.firstBank) { || location.bank >= memory[section.type].size() + typeInfo.firstBank) {
fatal( fatal(
"Invalid bank for %s section: 0x%02x", "Invalid bank for %s section \"%s\": %" PRIu32,
sectionTypeInfo[section.type].name.c_str(), sectionTypeInfo[section.type].name.c_str(),
section.name.c_str(),
location.bank location.bank
); );
} }

View File

@@ -71,9 +71,7 @@ void out_AddSection(Section const &section) {
}; };
uint32_t targetBank = section.bank - sectionTypeInfo[section.type].firstBank; uint32_t targetBank = section.bank - sectionTypeInfo[section.type].firstBank;
uint32_t minNbBanks = targetBank + 1; if (targetBank >= maxNbBanks[section.type]) {
if (minNbBanks > maxNbBanks[section.type]) {
fatal( fatal(
"Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")", "Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
section.name.c_str(), section.name.c_str(),
@@ -81,16 +79,14 @@ void out_AddSection(Section const &section) {
maxNbBanks[section.type] - 1 maxNbBanks[section.type] - 1
); );
} }
if (sections[section.type].size() <= targetBank) {
for (uint32_t i = sections[section.type].size(); i < minNbBanks; ++i) { sections[section.type].resize(targetBank + 1);
sections[section.type].emplace_back();
} }
// Insert section while keeping the list sorted by increasing org
std::deque<Section const *> &bankSections = std::deque<Section const *> &bankSections =
section.size ? sections[section.type][targetBank].sections section.size ? sections[section.type][targetBank].sections
: sections[section.type][targetBank].zeroLenSections; : sections[section.type][targetBank].zeroLenSections;
// Insert section while keeping the list sorted by increasing org
auto pos = bankSections.begin(); auto pos = bankSections.begin();
while (pos != bankSections.end() && (*pos)->org < section.org) { while (pos != bankSections.end() && (*pos)->org < section.org) {
++pos; ++pos;