Fixed #1218 (Improve check: incrementing uninitialized variable i++)

This commit is contained in:
Daniel Marjamäki 2010-01-10 09:09:37 +01:00
parent 19ba151531
commit b82cb2e41e
2 changed files with 13 additions and 0 deletions

View File

@ -1607,6 +1607,12 @@ private:
return &tok;
}
if (Token::Match(tok.previous(), "++|--") || Token::Match(tok.next(), "++|--"))
{
use(foundError, checks, &tok);
return &tok;
}
if (Token::Match(tok.previous(), "[;{}] %var% ="))
{
// using same variable rhs?

View File

@ -1076,6 +1076,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" int a;\n"
" a++;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int i;\n"