Fixed #5082 (False positive: (error) Possible null pointer dereference: p2)
This commit is contained in:
parent
47766736fc
commit
fc26de89a9
|
@ -1401,12 +1401,12 @@ private:
|
||||||
bool null;
|
bool null;
|
||||||
|
|
||||||
/** variable is set to null */
|
/** variable is set to null */
|
||||||
static void setnull(std::list<ExecutionPath *> &checks, const unsigned int varid) {
|
static void setnull(std::list<ExecutionPath *> &checks, const unsigned int varid, bool null) {
|
||||||
std::list<ExecutionPath *>::iterator it;
|
std::list<ExecutionPath *>::iterator it;
|
||||||
for (it = checks.begin(); it != checks.end(); ++it) {
|
for (it = checks.begin(); it != checks.end(); ++it) {
|
||||||
Nullpointer *c = dynamic_cast<Nullpointer *>(*it);
|
Nullpointer *c = dynamic_cast<Nullpointer *>(*it);
|
||||||
if (c && c->varId == varid)
|
if (c && c->varId == varid)
|
||||||
c->null = true;
|
c->null = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1483,8 +1483,8 @@ private:
|
||||||
dereference(checks, &tok);
|
dereference(checks, &tok);
|
||||||
else if (unknown && owner->inconclusiveFlag())
|
else if (unknown && owner->inconclusiveFlag())
|
||||||
dereference(checks, &tok);
|
dereference(checks, &tok);
|
||||||
if (Token::Match(tok.previous(), "[;{}=] %var% = 0 ;"))
|
if (Token::Match(tok.previous(), "[;{}=] %var% ="))
|
||||||
setnull(checks, tok.varId());
|
setnull(checks, tok.varId(), Token::simpleMatch(tok.tokAt(2), "0 ;"));
|
||||||
else if (!deref &&
|
else if (!deref &&
|
||||||
(!tok.previous()->isOp() || tok.previous()->str() == "&") &&
|
(!tok.previous()->isOp() || tok.previous()->str() == "&") &&
|
||||||
(!tok.next()->isConstOp() || tok.next()->str() == ">>"))
|
(!tok.next()->isConstOp() || tok.next()->str() == ">>"))
|
||||||
|
|
|
@ -55,6 +55,7 @@ private:
|
||||||
TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z)
|
TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z)
|
||||||
TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;)
|
TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;)
|
||||||
TEST_CASE(nullpointer23); // #4665 (false positive)
|
TEST_CASE(nullpointer23); // #4665 (false positive)
|
||||||
|
TEST_CASE(nullpointer24); // #5082 fp: chained assignment
|
||||||
TEST_CASE(nullpointer_cast); // #4692
|
TEST_CASE(nullpointer_cast); // #4692
|
||||||
TEST_CASE(nullpointer_castToVoid); // #3771
|
TEST_CASE(nullpointer_castToVoid); // #3771
|
||||||
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
|
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
|
||||||
|
@ -1241,6 +1242,15 @@ private:
|
||||||
TODO_ASSERT_EQUALS("","[test.cpp:4]: (error) Possible null pointer dereference: c\n", errout.str());
|
TODO_ASSERT_EQUALS("","[test.cpp:4]: (error) Possible null pointer dereference: c\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nullpointer24() { // #5083 - fp: chained assignment
|
||||||
|
check("void f(){\n"
|
||||||
|
" char *c = NULL;\n"
|
||||||
|
" x = c = new char[10];\n"
|
||||||
|
" *c = 0;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void nullpointer_cast() { // #4692
|
void nullpointer_cast() { // #4692
|
||||||
check("char *nasm_skip_spaces(const char *p) {\n"
|
check("char *nasm_skip_spaces(const char *p) {\n"
|
||||||
" if (p)\n"
|
" if (p)\n"
|
||||||
|
|
Loading…
Reference in New Issue