Fixed #3916 (false positive: uninitialized variable when using assignment and , in rhs)

This commit is contained in:
Daniel Marjamäki 2012-06-27 20:44:19 +02:00
parent 9da3373876
commit 2e3a08a8c1
2 changed files with 10 additions and 9 deletions

View File

@ -412,7 +412,7 @@ private:
if (var2->isPointer())
checks.push_back(new UninitVar(owner, var2, symbolDatabase, isC));
else if (var2->typeEndToken()->str() != ">") {
bool stdtype = isC;
bool stdtype = false; // TODO: change to isC to handle unknown types better
for (const Token* tok2 = var2->typeStartToken(); tok2 != var2->nameToken(); tok2 = tok2->next()) {
if (tok2->isStandardType()) {
stdtype = true;

View File

@ -84,13 +84,6 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("void foo() {\n"
" dfs a;\n"
" b = c - a;\n"
"}\n",
"test.c");
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("void foo() {\n"
" int a;\n"
" b = a - c;\n"
@ -310,7 +303,15 @@ private:
" return ret;\n"
"}\n",
"test.c");
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ret\n", errout.str());
TODO_ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ret\n", "", errout.str());
// #3916 - avoid false positive
checkUninitVar("void f(float x) {\n"
" union lf { long l; float f; } u_lf;\n"
" float hx = (u_lf.f = (x), u_lf.l);\n"
"}\n",
"test.c");
ASSERT_EQUALS("", errout.str());
}
checkUninitVar("void a()\n"