diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3be0a0025..1ec8df6e8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2431,7 +2431,7 @@ void CheckOther::nullPointerLinkedList() } --indentlevel4; } - else if (tok4->str() == "break") + else if (tok4->str() == "break" || tok4->str() == "return") break; } } diff --git a/test/testother.cpp b/test/testother.cpp index 55936796a..b0dfaf1c6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -925,6 +925,18 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkNullPointer("void f()\n" + "{\n" + " for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())\n" + " {\n" + " while (tok && tok->str() != \"{\")\n" + " tok = tok->next();\n" + " if (!tok)\n" + " return;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // dynamic_cast.. checkNullPointer("void foo(ABC *abc)\n" "{\n"