diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d3bbc7221..0cf970aff 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2821,6 +2821,20 @@ private: return ExecutionPath::parseCondition(tok, checks); } + + + void parseLoopBody(const Token *tok, std::list &checks) const + { + while (tok) + { + if (tok->str() == "{" || tok->str() == "}") + return; + const Token *next = parse(*tok, checks); + if (next) + tok = tok->next(); + } + } + }; diff --git a/test/testother.cpp b/test/testother.cpp index 0d45a49ab..2cf84ec19 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1100,6 +1100,14 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n" "[test.cpp:6]: (error) Null pointer dereference\n", errout.str()); + // loops.. + checkNullPointer("void f() {\n" + " int *p = 0;\n" + " for (int i = 0; i < 10; ++i) {\n" + " int x = *p + 1;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); } void nullpointer7()