diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0b2dbdeaf..ff885281f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2394,7 +2394,7 @@ void CheckOther::nullPointerStructByDeRefAndChec() else if (tok2->str() == "}") { - if (indentlevel2 == 0) + if (indentlevel2 <= 1) break; --indentlevel2; } diff --git a/test/testother.cpp b/test/testother.cpp index 6c1ce6060..343fad459 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -781,6 +781,18 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // ticket #1923 - no false positive when using else if + checkNullPointer("void f(A *a)\n" + "{\n" + " if (a->x == 1)\n" + " {\n" + " a = a->next;\n" + " }\n" + " else if (a->x == 2) { }\n" + " if (a) { }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void nullpointer2()