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; return &tok;
} }
if (Token::Match(tok.previous(), "++|--") || Token::Match(tok.next(), "++|--"))
{
use(foundError, checks, &tok);
return &tok;
}
if (Token::Match(tok.previous(), "[;{}] %var% =")) if (Token::Match(tok.previous(), "[;{}] %var% ="))
{ {
// using same variable rhs? // using same variable rhs?

View File

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