diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index b10522b3a..4fbe58785 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -288,7 +288,8 @@ void CheckNullPointer::nullPointerByDeRefAndChec() if (Token::Match(tok, "%num%|%char%|%str%")) continue; - if (!isNullablePointer(tok, mSettings)) + if (!isNullablePointer(tok, mSettings) || + (tok->str() == "." && isNullablePointer(tok->astOperand2(), mSettings) && tok->astOperand2()->getValue(0))) // avoid duplicate warning continue; // Can pointer be NULL? diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 755ae7983..37a017cde 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -667,6 +667,16 @@ private: " *new int;\n" "}\n", /*inconclusive*/ true); ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n", errout.str()); + + check("void f() {\n" // #5475 + " std::string(\"a\") + \"a\";\n" + "}\n" + "void f(std::string& a) {\n" + " a.erase(3) + \"suf\";\n" + "}\n", /*inconclusive*/ true); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n" + "[test.cpp:5]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n", + errout.str()); } void vardecl() { diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 239be7e6e..45c13b658 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -993,6 +993,11 @@ private: " if (p);\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("struct S { struct T { char c; } *p; };\n" // #6541 + "char f(S* s) { return s->p ? 'a' : s->p->c; }\n"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: p.\n", + errout.str()); } void nullpointer5() {