From f55d72e82107095ab007da4fdf4e953dca481369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 31 Dec 2019 14:57:42 +0100 Subject: [PATCH] Verification; uninitialized local variable --- lib/exprengine.cpp | 9 ++++++--- test/testsuites/danmar-verify/uninit.c | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 6f872f606..9bcffe2c6 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1464,8 +1464,7 @@ static void execute(const Token *start, const Token *end, Data &data) tok = tok->tokAt(2); continue; } - } - if (tok->variable()->isArray()) { + } else if (tok->variable()->isArray()) { data.assignValue(tok, tok->varId(), std::make_shared(&data, tok->variable())); if (Token::Match(tok, "%name% [")) tok = tok->linkAt(1); @@ -1657,7 +1656,11 @@ static ExprEngine::ValuePtr createVariableValue(const Variable &var, Data &data) if (var.isArray()) return std::make_shared(&data, &var); 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(); + else + value = getValueRangeFromValueType(data.getNewSymbolName(), valueType, *data.settings); data.addConstraints(value, var.nameToken()); return value; } diff --git a/test/testsuites/danmar-verify/uninit.c b/test/testsuites/danmar-verify/uninit.c index a7249b3cb..f1cbe94a2 100644 --- a/test/testsuites/danmar-verify/uninit.c +++ b/test/testsuites/danmar-verify/uninit.c @@ -16,6 +16,12 @@ int array2() { return a[2][3]; } +void local1() { + int x; + // cppcheck-suppress verificationUninit + return x; +} + int pointer1(int *p) { // cppcheck-suppress verificationUninit return *p;