Verification; Fixed false negative when global variable is changed by function call

This commit is contained in:
Daniel Marjamäki 2020-01-09 18:50:29 +01:00
parent 2137f1ead9
commit 84b4f0f6ab
1 changed files with 15 additions and 1 deletions

View File

@ -165,7 +165,7 @@ namespace {
, callbacks(callbacks)
, mTrackExecution(trackExecution)
, mDataIndex(trackExecution->getNewDataIndex()) {}
typedef std::map<nonneg int, std::shared_ptr<ExprEngine::Value>> Memory;
typedef std::map<nonneg int, ExprEngine::ValuePtr> Memory;
Memory memory;
int * const symbolValueIndex;
const Tokenizer * const tokenizer;
@ -198,6 +198,19 @@ namespace {
structVal->member[memberName] = value;
}
void functionCall() {
// Remove values for global variables
const SymbolDatabase *symbolDatabase = tokenizer->getSymbolDatabase();
for (std::map<nonneg int, ExprEngine::ValuePtr>::iterator it = memory.begin(); it != memory.end();) {
unsigned int varid = it->first;
const Variable *var = symbolDatabase->getVariableFromVarId(varid);
if (var->isGlobal())
it = memory.erase(it);
else
++it;
}
}
std::string getNewSymbolName() OVERRIDE {
return "$" + std::to_string(++(*symbolValueIndex));
}
@ -1181,6 +1194,7 @@ static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data)
auto val = getValueRangeFromValueType(data.getNewSymbolName(), tok->valueType(), *data.settings);
call(data.callbacks, tok, val, &data);
data.functionCall();
return val;
}