ExprEngine: Improved handling of struct member assignments in loops

This commit is contained in:
Daniel Marjamäki 2019-10-14 22:03:55 +02:00
parent 60de5e12dd
commit d98ac017f7
1 changed files with 7 additions and 4 deletions

View File

@ -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<ExprEngine::StructValue>(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<ExprEngine::StructValue>(structVal1);
if (!structVal)
throw VerifyException(tok2, "Unhandled assignment in loop");
data.assignStructMember(tok2, &*structVal, memberName, memberValue);
continue;
}