Fixed #4165 (False positive:(error) Uninitialized variable: here)

This commit is contained in:
Daniel Marjamäki 2012-09-25 20:45:42 +02:00
parent 95b6288d25
commit 96b1890797
2 changed files with 7 additions and 1 deletions

View File

@ -1325,7 +1325,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer) const
return false;
}
if (Token::Match(vartok->next(), "++|--|%op%"))
if (Token::Match(vartok->next(), "++|--|%op%") && !Token::simpleMatch(vartok->tokAt(-2), "( &"))
return true;
if (vartok->strAt(1) == "]")

View File

@ -2002,6 +2002,12 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar2("void f() {\n" // #4165 - fp when & is used as address-of in condition
" int x;\n"
" if (&x < p) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
// ?:
checkUninitVar2("int f(int *ptr) {\n"
" int a;\n"