From 00b091443612b6fcb15956cbfa654d9d56165d8f Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 13 Aug 2024 23:29:24 +0200 Subject: [PATCH] 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. --- src/link/sdas_obj.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/link/sdas_obj.cpp b/src/link/sdas_obj.cpp index 2e2b7c90..9f5a5e7e 100644 --- a/src/link/sdas_obj.cpp +++ b/src/link/sdas_obj.cpp @@ -223,6 +223,7 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector getToken(nullptr, "'H' line is too short"); uint32_t expectedNbSymbols = parseNumber(where, lineNo, token, numberType); + fileSymbols.reserve(expectedNbSymbols); expectToken("global", 'H'); @@ -343,13 +344,15 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector } case 'S': { - if (fileSymbols.size() == expectedNbSymbols) - warning( + if (fileSymbols.size() == expectedNbSymbols) { + error( &where, lineNo, "Got more 'S' lines than the expected %" PRIu32, expectedNbSymbols ); + break; // Refuse processing the line further. + } Symbol &symbol = fileSymbols.emplace_back(); // Init other members