Uninitialized var: Fixed false negatives for self assignment
This commit is contained in:
parent
2a640a59c2
commit
d342387b95
|
@ -1685,6 +1685,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp
|
|||
}
|
||||
}
|
||||
|
||||
if (Token::Match(vartok->previous(), "= %var% ;|%cop%"))
|
||||
return true;
|
||||
|
||||
bool unknown = false;
|
||||
if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) {
|
||||
// function parameter?
|
||||
|
|
|
@ -2081,6 +2081,12 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar2("int f() {\n"
|
||||
" int x;\n"
|
||||
" x = x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" struct ABC *abc;\n"
|
||||
" abc->a = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue