diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 5f31ff60e..e4173bd84 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -444,8 +444,8 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec() break; // Check if pointer is null. - // TODO: false negatives for something like: "if (p &&.."? - else if (Token::Match(tok2, "if ( !| %varid% )", varid1)) + // TODO: false negatives for "if (!p || .." + else if (Token::Match(tok2, "if ( !| %varid% )|&&", varid1)) { // Is this variable a pointer? if (isPointer(varid1)) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index e106577c2..f6e124fa9 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -215,6 +215,13 @@ private: "}\n"); TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 3\n", "", errout.str()); + check("void foo(ABC *abc) {\n" + " abc->a = 0;\n" + " if (abc && abc->b == 0)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 3\n", errout.str()); + // ok dereferencing in a condition check("void foo(struct ABC *abc)\n" "{\n"