mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Reserve space to avoid file sym array realloc
This line was missing; in its absence, as soon as the array reallocs, all registered symbol pointers are invalidated, leading to a crash (e.g. when generating a sym file). Made the reallocation check into a hard error, too. Since fileSymbols gets registered with each section, we would have to change that, and then it cascades throughout all of RGBLINK. This will be handled correctly in the Rust port.
This commit is contained in:
@@ -223,6 +223,7 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector<Symbol>
|
|||||||
|
|
||||||
getToken(nullptr, "'H' line is too short");
|
getToken(nullptr, "'H' line is too short");
|
||||||
uint32_t expectedNbSymbols = parseNumber(where, lineNo, token, numberType);
|
uint32_t expectedNbSymbols = parseNumber(where, lineNo, token, numberType);
|
||||||
|
fileSymbols.reserve(expectedNbSymbols);
|
||||||
|
|
||||||
expectToken("global", 'H');
|
expectToken("global", 'H');
|
||||||
|
|
||||||
@@ -343,13 +344,15 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector<Symbol>
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'S': {
|
case 'S': {
|
||||||
if (fileSymbols.size() == expectedNbSymbols)
|
if (fileSymbols.size() == expectedNbSymbols) {
|
||||||
warning(
|
error(
|
||||||
&where,
|
&where,
|
||||||
lineNo,
|
lineNo,
|
||||||
"Got more 'S' lines than the expected %" PRIu32,
|
"Got more 'S' lines than the expected %" PRIu32,
|
||||||
expectedNbSymbols
|
expectedNbSymbols
|
||||||
);
|
);
|
||||||
|
break; // Refuse processing the line further.
|
||||||
|
}
|
||||||
Symbol &symbol = fileSymbols.emplace_back();
|
Symbol &symbol = fileSymbols.emplace_back();
|
||||||
|
|
||||||
// Init other members
|
// Init other members
|
||||||
|
|||||||
Reference in New Issue
Block a user