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:
ISSOtm
2024-08-13 23:29:24 +02:00
committed by Eldred Habert
parent 60c03ec1e3
commit 00b0914436

View File

@@ -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