Null pointers: Better handling of loops
This commit is contained in:
parent
40aeb17738
commit
8f707e5e46
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue