Fixed #3463 (Uninitialized variable variable pointer)

This commit is contained in:
Daniel Marjamäki 2012-01-02 11:25:13 +01:00
parent 112873e876
commit 01759b03f9
2 changed files with 8 additions and 1 deletions

View File

@ -1252,7 +1252,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer) const
return false;
}
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=]")) {
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
return true;
}
}

View File

@ -1752,6 +1752,13 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
// ?:
checkUninitVar2("int f(int *ptr) {\n"
" int a;\n"
" int *p = ptr ? ptr : &a;\n"
"}");
ASSERT_EQUALS("", errout.str());
// = { .. }
checkUninitVar2("int f() {\n"
" int a;\n"