fix 9296: false negative uninit variable (#2663)
This commit is contained in:
parent
d64631219b
commit
79c3af56e4
|
@ -1112,6 +1112,10 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
|
|||
if (vartok->strAt(1) == "]")
|
||||
return true;
|
||||
|
||||
const Token *astParent = vartok->astParent();
|
||||
if (astParent && (astParent->tokType() == Token::Type::eBitOp) && (astParent->isBinaryOp()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -703,6 +703,29 @@ private:
|
|||
" return (*sink)[0];\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #9296
|
||||
checkUninitVar("void f(void)\n"
|
||||
"{\n"
|
||||
" int x;\n"
|
||||
" int z = (x) & ~__round_mask(1, 1);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar("void f(void)\n"
|
||||
"{\n"
|
||||
" int x;\n"
|
||||
" int z = (x) | ~__round_mask(1, 1);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar("int __round_mask(int, int);\n"
|
||||
"void f(void)\n"
|
||||
"{\n"
|
||||
" int x;\n"
|
||||
" int* z = &x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar_warn_once() {
|
||||
|
|
Loading…
Reference in New Issue