Fixed #4734 (False 'Possible null pointer dereference')
This commit is contained in:
parent
de8ee5b042
commit
079d22fbee
|
@ -762,6 +762,19 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
|||
// Variable id for pointer
|
||||
const unsigned int varid(vartok->varId());
|
||||
|
||||
// bailout for while scope if pointer is assigned inside the loop
|
||||
if (i->type == Scope::eWhile) {
|
||||
bool assign = false;
|
||||
for (const Token *tok2 = i->classStart; tok2 && tok2 != i->classEnd; tok2 = tok2->next()) {
|
||||
if (Token::Match(tok2, "%varid% =", varid)) {
|
||||
assign = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (assign)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Name of pointer
|
||||
const std::string& varname(vartok->str());
|
||||
|
||||
|
|
|
@ -587,6 +587,19 @@ private:
|
|||
"}");
|
||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||
|
||||
// while
|
||||
check("void f(int *p) {\n"
|
||||
" *p = 0;\n"
|
||||
" while (p) { p = 0; }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(int *p) {\n"
|
||||
" *p = 0;\n"
|
||||
" while (p) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||
|
||||
// Ticket #3125
|
||||
check("void foo(ABC *p)\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue