Fix a false positive reported by scan-build

Arguably this also makes the logic a little clearer, so might as well
This commit is contained in:
ISSOtm
2024-08-23 01:34:36 +02:00
parent 44332ff4be
commit 77129b9e80

View File

@@ -128,7 +128,7 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
std::deque<FreeSpace> &bankMem = memory[section.type][location.bank - typeInfo.firstBank]; std::deque<FreeSpace> &bankMem = memory[section.type][location.bank - typeInfo.firstBank];
size_t spaceIdx = 0; size_t spaceIdx = 0;
if (spaceIdx < bankMem.size()) if (spaceIdx < bankMem.size()) {
location.address = bankMem[spaceIdx].address; location.address = bankMem[spaceIdx].address;
// Process locations in that bank // Process locations in that bank
@@ -169,6 +169,7 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
// Try again with the new location/free space combo // Try again with the new location/free space combo
} }
}
// Try again in the next bank, if one is available. // Try again in the next bank, if one is available.
// Try scrambled banks in descending order until no bank in the scrambled range is // Try scrambled banks in descending order until no bank in the scrambled range is
@@ -182,7 +183,8 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
location.bank = scrambleROMX + 1; location.bank = scrambleROMX + 1;
else else
return -1; return -1;
} else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX && location.bank <= scrambleWRAMX) { } else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX
&& location.bank <= scrambleWRAMX) {
if (location.bank > typeInfo.firstBank) if (location.bank > typeInfo.firstBank)
location.bank--; location.bank--;
else if (scrambleWRAMX < typeInfo.lastBank) else if (scrambleWRAMX < typeInfo.lastBank)
@@ -246,8 +248,8 @@ static void placeSection(Section &section) {
bankMem.insert( bankMem.insert(
bankMem.begin() + spaceIdx + 1, bankMem.begin() + spaceIdx + 1,
{.address = (uint16_t)(section.org + section.size), {.address = (uint16_t)(section.org + section.size),
.size = .size = (uint16_t)(freeSpace.address + freeSpace.size - section.org - section.size)
(uint16_t)(freeSpace.address + freeSpace.size - section.org - section.size)} }
); );
// **`freeSpace` cannot be reused from this point on**, because `bankMem.insert` // **`freeSpace` cannot be reused from this point on**, because `bankMem.insert`
// invalidates all references to itself! // invalidates all references to itself!