UninitVar: Don't warn for inconclusive values

This commit is contained in:
Daniel Marjamäki 2017-04-28 21:09:56 +02:00
parent a0a8f8ddd6
commit 06102cb3d7
2 changed files with 11 additions and 3 deletions

View File

@ -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());
}
}
}

View File

@ -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() {