diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 4bd058f45..c29c72897 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -461,7 +461,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec() break; } - if (tok1->varId() == varid) + if (tok1->varId() == varid && !Token::Match(tok1->previous(), "[?:]")) { // unknown : this is set by isPointerDeRef if it is // uncertain diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 7f5020339..e610ab618 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -397,6 +397,14 @@ private: " ;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void foo(struct ABC *abc)\n" + "{\n" + " abc = abc ? abc->next : 0;\n" + " if (!abc)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void nullpointer5()