mirror of
https://github.com/gbdev/rgbds.git
synced 2025-12-06 01:37:47 +00:00
Fix bug where an object's invalid ROMX bank of 0 could break rgblink (#1868)
This commit is contained in:
@@ -122,8 +122,9 @@ static std::optional<size_t> getPlacement(Section const §ion, 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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,9 +71,7 @@ void out_AddSection(Section const §ion) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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 §ion) {
|
|||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user