Uninitialized var: Fixed false negatives for self assignment

This commit is contained in:
Daniel Marjamäki 2013-11-16 18:07:33 +01:00
parent 2a640a59c2
commit d342387b95
2 changed files with 9 additions and 0 deletions

View File

@ -1685,6 +1685,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp
} }
} }
if (Token::Match(vartok->previous(), "= %var% ;|%cop%"))
return true;
bool unknown = false; bool unknown = false;
if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) { if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) {
// function parameter? // function parameter?

View File

@ -2081,6 +2081,12 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar2("int f() {\n"
" int x;\n"
" x = x;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar2("void f() {\n" checkUninitVar2("void f() {\n"
" struct ABC *abc;\n" " struct ABC *abc;\n"
" abc->a = 0;\n" " abc->a = 0;\n"