CheckNullPointer::isPointerDeRef: Improve handling of static member variables and functions
This commit is contained in:
parent
e875146060
commit
f7824bfd00
|
@ -168,6 +168,16 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
|
||||||
|
|
||||||
// read/write member variable
|
// read/write member variable
|
||||||
if (firstOperand && parent->str() == "." && (!parent->astParent() || parent->astParent()->str() != "&")) {
|
if (firstOperand && parent->str() == "." && (!parent->astParent() || parent->astParent()->str() != "&")) {
|
||||||
|
const Token* rightTok = parent->astOperand2();
|
||||||
|
if (rightTok) {
|
||||||
|
const Function* func = rightTok->function();
|
||||||
|
if (func && func->isStatic)
|
||||||
|
return false;
|
||||||
|
const Variable* var = rightTok->variable();
|
||||||
|
if (var && var->isStatic()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!parent->astParent() || parent->astParent()->str() != "(" || parent->astParent() == tok->previous())
|
if (!parent->astParent() || parent->astParent()->str() != "(" || parent->astParent() == tok->previous())
|
||||||
return true;
|
return true;
|
||||||
unknown = true;
|
unknown = true;
|
||||||
|
|
|
@ -3173,6 +3173,30 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("class Element {\n"
|
||||||
|
" static int v;\n"
|
||||||
|
"};\n"
|
||||||
|
"void test() {\n"
|
||||||
|
" Element *element; element->v;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("class Element {\n"
|
||||||
|
" void f() { }\n"
|
||||||
|
"};\n"
|
||||||
|
"void test() {\n"
|
||||||
|
" Element *element; element->f();\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("class Element {\n"
|
||||||
|
" int v;\n"
|
||||||
|
"};\n"
|
||||||
|
"void test() {\n"
|
||||||
|
" Element *element; element->v;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: element\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar2("void f() {\n" // #4911 - bad simplification => don't crash
|
checkUninitVar2("void f() {\n" // #4911 - bad simplification => don't crash
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" do { a=do_something() } while (a);\n"
|
" do { a=do_something() } while (a);\n"
|
||||||
|
|
Loading…
Reference in New Issue