From d98ac017f7f2cd392bc6913f0ff55e7c3a4ae550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 14 Oct 2019 22:03:55 +0200 Subject: [PATCH] ExprEngine: Improved handling of struct member assignments in loops --- lib/exprengine.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 9f1feb84d..823854829 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1258,10 +1258,6 @@ static void execute(const Token *start, const Token *end, Data &data) if (!structScope) throw VerifyException(tok2, "Unhandled assignment in loop"); const std::string &memberName = tok2->previous()->str(); - ExprEngine::ValuePtr structVal1 = data.getValue(structToken->varId(), structToken->valueType(), structToken); - auto structVal = std::dynamic_pointer_cast(structVal1); - if (!structVal) - throw VerifyException(tok2, "Unhandled assignment in loop"); ExprEngine::ValuePtr memberValue; for (const Variable &member : structScope->varlist) { if (memberName == member.name() && member.valueType()) { @@ -1272,6 +1268,13 @@ static void execute(const Token *start, const Token *end, Data &data) if (!memberValue) throw VerifyException(tok2, "Unhandled assignment in loop"); + ExprEngine::ValuePtr structVal1 = data.getValue(structToken->varId(), structToken->valueType(), structToken); + if (!structVal1) + structVal1 = createVariableValue(*structToken->variable(), data); + auto structVal = std::dynamic_pointer_cast(structVal1); + if (!structVal) + throw VerifyException(tok2, "Unhandled assignment in loop"); + data.assignStructMember(tok2, &*structVal, memberName, memberValue); continue; }