Fixed #3159 (Uninitialized variable false positive)

This commit is contained in:
Daniel Marjamäki 2011-10-02 20:38:58 +02:00
parent 480c403511
commit 417dc1ff2a
2 changed files with 14 additions and 1 deletions

View File

@ -498,7 +498,7 @@ private:
bool assignment = false;
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next())
{
if (tok2->str() == "=" || tok2->str() == ">>" || tok2->str() == "?")
if (tok2->str() == "=" || tok2->str() == ">>" || tok2->str() == "?" || Token::Match(tok2, "(|, &"))
{
assignment = true;
break;

View File

@ -1568,6 +1568,19 @@ private:
" buf[1] = buf[0];\n"
"}");
ASSERT_EQUALS("", errout.str());
// #3159 - initialization by function
checkUninitVar("static int isnumber(const char *arg) {\n"
" char *p;\n"
" return strtod(arg, &p) != 0 || p != arg;\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("static int isnumber(const char *arg) {\n"
" char *p;\n"
" return strtod(&arg) != 0 || p != arg;\n"
"}");
TODO_ASSERT_EQUALS("error", "", errout.str());
}
// valid and invalid use of 'int a(int x) { return x + x; }'