Fix issue 9439: false positive: unique_ptr and nullPointerRedundantCheck (#2346)

This commit is contained in:
Paul Fultz II 2019-11-10 02:44:59 -06:00 committed by Daniel Marjamäki
parent c1da6c7dd2
commit 6f29e299fc
3 changed files with 11 additions and 2 deletions

View File

@ -194,7 +194,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set
return false;
// read/write member variable
if (firstOperand && parent->str() == "." && (!parent->astParent() || parent->astParent()->str() != "&")) {
if (firstOperand && parent->originalName() == "->" && (!parent->astParent() || parent->astParent()->str() != "&")) {
if (!parent->astParent() || parent->astParent()->str() != "(" || parent->astParent() == tok->previous())
return true;
unknown = true;

View File

@ -2596,6 +2596,15 @@ private:
" var->f();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9439
check("char* g();\n"
"char* f() {\n"
" std::unique_ptr<char> x(g());\n"
" if( x ) {}\n"
" return x.release();\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}
void functioncall() { // #3443 - function calls

View File

@ -4503,7 +4503,7 @@ private:
"\n"
"int main() {\n"
" Foo* foo;\n"
" foo.b\n"
" foo->b\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: foo\n", errout.str());
}