mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
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:
@@ -128,46 +128,47 @@ static ssize_t getPlacement(Section const §ion, 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
|
||||||
while (spaceIdx < bankMem.size()) {
|
while (spaceIdx < bankMem.size()) {
|
||||||
// If that location is OK, return it
|
// If that location is OK, return it
|
||||||
if (isLocationSuitable(section, bankMem[spaceIdx], location))
|
if (isLocationSuitable(section, bankMem[spaceIdx], location))
|
||||||
return spaceIdx;
|
return spaceIdx;
|
||||||
|
|
||||||
// Go to the next *possible* location
|
// Go to the next *possible* location
|
||||||
if (section.isAddressFixed) {
|
if (section.isAddressFixed) {
|
||||||
// If the address is fixed, there can be only
|
// If the address is fixed, there can be only
|
||||||
// one candidate block per bank; if we already
|
// one candidate block per bank; if we already
|
||||||
// reached it, give up.
|
// reached it, give up.
|
||||||
if (location.address < section.org)
|
if (location.address < section.org)
|
||||||
location.address = section.org;
|
location.address = section.org;
|
||||||
else
|
else
|
||||||
break; // Try again in next bank
|
break; // Try again in next bank
|
||||||
} else if (section.isAlignFixed) {
|
} else if (section.isAlignFixed) {
|
||||||
// Move to next aligned location
|
// Move to next aligned location
|
||||||
// Move back to alignment boundary
|
// Move back to alignment boundary
|
||||||
location.address -= section.alignOfs;
|
location.address -= section.alignOfs;
|
||||||
// Ensure we're there (e.g. on first check)
|
// Ensure we're there (e.g. on first check)
|
||||||
location.address &= ~section.alignMask;
|
location.address &= ~section.alignMask;
|
||||||
// Go to next align boundary and add offset
|
// Go to next align boundary and add offset
|
||||||
location.address += section.alignMask + 1 + section.alignOfs;
|
location.address += section.alignMask + 1 + section.alignOfs;
|
||||||
} else {
|
} else {
|
||||||
// Any location is fine, so, next free block
|
// Any location is fine, so, next free block
|
||||||
spaceIdx++;
|
spaceIdx++;
|
||||||
if (spaceIdx < bankMem.size())
|
if (spaceIdx < bankMem.size())
|
||||||
location.address = bankMem[spaceIdx].address;
|
location.address = bankMem[spaceIdx].address;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If that location is past the current block's end,
|
||||||
|
// go forwards until that is no longer the case.
|
||||||
|
while (spaceIdx < bankMem.size()
|
||||||
|
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size)
|
||||||
|
spaceIdx++;
|
||||||
|
|
||||||
|
// Try again with the new location/free space combo
|
||||||
}
|
}
|
||||||
|
|
||||||
// If that location is past the current block's end,
|
|
||||||
// go forwards until that is no longer the case.
|
|
||||||
while (spaceIdx < bankMem.size()
|
|
||||||
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size)
|
|
||||||
spaceIdx++;
|
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -182,7 +183,8 @@ static ssize_t getPlacement(Section const §ion, 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 §ion) {
|
|||||||
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!
|
||||||
|
|||||||
Reference in New Issue
Block a user