fix 9296: false negative uninit variable (#2663)

This commit is contained in:
miltolstoy 2020-05-28 22:28:18 +03:00 committed by GitHub
parent d64631219b
commit 79c3af56e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -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;
}

View File

@ -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() {