Permalink
Browse files

Uninitialized variables: Another fix for false positives when it's kn…

…own that inner conditions are true
  • Loading branch information...
1 parent 05fc77c commit 47c7e346aabf4f07a42da840191a8246df48034f @danmar committed Feb 6, 2012
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/checkuninitvar.cpp
  2. +10 −0 test/testuninitvar.cpp
View
@@ -1113,8 +1113,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
}
// assignment with nonzero constant..
- if (Token::Match(tok, "[;{}] %var% = - %var% ;") && tok->next()->varId() > 0)
- notzero.insert(tok->next()->varId());
+ if (Token::Match(tok->previous(), "[;{}] %var% = - %var% ;") && tok->varId() > 0)
+ notzero.insert(tok->varId());
// Inner scope..
if (Token::simpleMatch(tok, "if (")) {
View
@@ -1893,6 +1893,16 @@ class TestUninitVar : public TestFixture {
"}\n");
ASSERT_EQUALS("", errout.str());
+ checkUninitVar2("void f() {\n"
+ " int i, y;\n"
+ " if (x) {\n"
+ " y = -ENOMEM;\n"
+ " if (y != 0) return;\n"
+ " i++;\n"
+ " }\n"
+ "}\n");
+ ASSERT_EQUALS("", errout.str());
+
// for, while
checkUninitVar2("void f() {\n"
" int x;\n"

0 comments on commit 47c7e34

Please sign in to comment.