Verification; uninitialized local variable

This commit is contained in:
Daniel Marjamäki 2019-12-31 14:57:42 +01:00
parent c86a2d6e15
commit f55d72e821
2 changed files with 12 additions and 3 deletions

View File

@ -1464,8 +1464,7 @@ static void execute(const Token *start, const Token *end, Data &data)
tok = tok->tokAt(2); tok = tok->tokAt(2);
continue; continue;
} }
} } else if (tok->variable()->isArray()) {
if (tok->variable()->isArray()) {
data.assignValue(tok, tok->varId(), std::make_shared<ExprEngine::ArrayValue>(&data, tok->variable())); data.assignValue(tok, tok->varId(), std::make_shared<ExprEngine::ArrayValue>(&data, tok->variable()));
if (Token::Match(tok, "%name% [")) if (Token::Match(tok, "%name% ["))
tok = tok->linkAt(1); tok = tok->linkAt(1);
@ -1657,7 +1656,11 @@ static ExprEngine::ValuePtr createVariableValue(const Variable &var, Data &data)
if (var.isArray()) if (var.isArray())
return std::make_shared<ExprEngine::ArrayValue>(&data, &var); return std::make_shared<ExprEngine::ArrayValue>(&data, &var);
if (valueType->isIntegral() || valueType->isFloat()) { if (valueType->isIntegral() || valueType->isFloat()) {
auto value = getValueRangeFromValueType(data.getNewSymbolName(), valueType, *data.settings); ExprEngine::ValuePtr value;
if (var.isLocal() && !var.isStatic())
value = std::make_shared<ExprEngine::UninitValue>();
else
value = getValueRangeFromValueType(data.getNewSymbolName(), valueType, *data.settings);
data.addConstraints(value, var.nameToken()); data.addConstraints(value, var.nameToken());
return value; return value;
} }

View File

@ -16,6 +16,12 @@ int array2() {
return a[2][3]; return a[2][3];
} }
void local1() {
int x;
// cppcheck-suppress verificationUninit
return x;
}
int pointer1(int *p) { int pointer1(int *p) {
// cppcheck-suppress verificationUninit // cppcheck-suppress verificationUninit
return *p; return *p;