Fixed #4512 (Improve check: Uninitialized variable not detected)
This commit is contained in:
parent
04ceae7ea7
commit
8738223e82
|
@ -1498,6 +1498,10 @@ bool CheckUninitVar::isVariableUsage(const Scope* scope, const Token *vartok, bo
|
|||
if ((pointer || address) && Token::Match(argStart, "const %type% * %var% [,)]"))
|
||||
return true;
|
||||
}
|
||||
|
||||
} else if (Token::Match(start->previous(), "if|while|for")) {
|
||||
// control-flow statement reading the variable "by value"
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2010,6 +2010,12 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// using uninit var in condition
|
||||
checkUninitVar2("void f(void) {\n"
|
||||
" int x;\n"
|
||||
" if (x) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
" if (1 == (3 & x)) { }\n"
|
||||
|
|
Loading…
Reference in New Issue