From aba18567866da23b8778a9e53b209bcf15d1c4f9 Mon Sep 17 00:00:00 2001 From: TimQu Date: Thu, 11 Oct 2018 16:05:20 +0200 Subject: [PATCH] JaniParser: fixed an issue related to using constants in the definition of other constants. --- src/storm-parsers/parser/JaniParser.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/storm-parsers/parser/JaniParser.cpp b/src/storm-parsers/parser/JaniParser.cpp index d38d8cd44..dbbc4d064 100644 --- a/src/storm-parsers/parser/JaniParser.cpp +++ b/src/storm-parsers/parser/JaniParser.cpp @@ -129,13 +129,13 @@ namespace storm { size_t constantsCount = parsedStructure.count("constants"); STORM_LOG_THROW(constantsCount < 2, storm::exceptions::InvalidJaniException, "Constant-declarations can be given at most once."); if (constantsCount == 1) { + // Reserve enough space to make sure that pointers to constants remain valid after adding new ones. + model.getConstants().reserve(parsedStructure.at("constants").size()); for (auto const &constStructure : parsedStructure.at("constants")) { std::shared_ptr constant = parseConstant(constStructure, scope.refine("constants[" + std::to_string(constants.size()) + "]")); model.addConstant(*constant); - } - // Insert references after adding all constants to make sure that they remain valid - for (auto const& constant : model.getConstants()) { - constants.emplace(constant.getName(), &constant); + assert(model.getConstants().back().getName() == constant->getName()); + constants.emplace(constant->getName(), &model.getConstants().back()); } }