Null pointers: Better handling of loops

This commit is contained in:
Daniel Marjamäki 2010-10-24 18:51:14 +02:00
parent 40aeb17738
commit 8f707e5e46
2 changed files with 22 additions and 0 deletions

View File

@ -2821,6 +2821,20 @@ private:
return ExecutionPath::parseCondition(tok, checks);
}
void parseLoopBody(const Token *tok, std::list<ExecutionPath *> &checks) const
{
while (tok)
{
if (tok->str() == "{" || tok->str() == "}")
return;
const Token *next = parse(*tok, checks);
if (next)
tok = tok->next();
}
}
};

View File

@ -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()