Fixed #1218 (Improve check: incrementing uninitialized variable i++)
This commit is contained in:
parent
19ba151531
commit
b82cb2e41e
|
@ -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?
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue