From 06102cb3d7dca9ba71181790a588f0842520b4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 28 Apr 2017 21:09:56 +0200 Subject: [PATCH] UninitVar: Don't warn for inconclusive values --- lib/checkuninitvar.cpp | 7 ++++--- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f7246445e..71d606d8b 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1208,13 +1208,14 @@ void CheckUninitVar::valueFlowUninit() if (!scope->isExecutable()) continue; for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { - if (!tok->variable()) + if (!tok->variable() || tok->values().size() != 1U) continue; - if (tok->values().size() != 1U || tok->values().front().valueType != ValueFlow::Value::UNINIT) + const ValueFlow::Value &v = tok->values().front(); + if (v.valueType != ValueFlow::Value::UNINIT || v.inconclusive) continue; if (!isVariableUsage(tok, tok->variable()->isPointer(), NO_ALLOC)) continue; - uninitvarError(tok,tok->str()); + uninitvarError(tok, tok->str()); } } } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index c25971e19..72d2c9c28 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3816,6 +3816,13 @@ private: " switch (x) {}\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str()); + + checkUninitVar("int f() {\n" + " int x;\n" + " init(x);\n" + " return x;\n" // TODO: inconclusive ? + "}"); + ASSERT_EQUALS("", errout.str()); } void isVariableUsageDeref() {