Fixed #3591
This commit is contained in:
parent
df0cb89a40
commit
2e13a51d08
|
@ -1208,7 +1208,7 @@ private:
|
||||||
if (Token::Match(tok.previous(), "[;{}=] %var% = 0 ;"))
|
if (Token::Match(tok.previous(), "[;{}=] %var% = 0 ;"))
|
||||||
setnull(checks, tok.varId());
|
setnull(checks, tok.varId());
|
||||||
else if (!deref &&
|
else if (!deref &&
|
||||||
!tok.previous()->isOp() && !tok.previous()->isAssignmentOp() &&
|
(!tok.previous()->isOp() || tok.previous()->str() == "&") && !tok.previous()->isAssignmentOp() &&
|
||||||
(!tok.next()->isOp() || tok.next()->str() == ">>"))
|
(!tok.next()->isOp() || tok.next()->str() == ">>"))
|
||||||
bailOutVar(checks, tok.varId()); // If its possible that the pointers value changes, bail out.
|
bailOutVar(checks, tok.varId()); // If its possible that the pointers value changes, bail out.
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ private:
|
||||||
TEST_CASE(nullpointer13); // ticket #1708
|
TEST_CASE(nullpointer13); // ticket #1708
|
||||||
TEST_CASE(nullpointer14);
|
TEST_CASE(nullpointer14);
|
||||||
TEST_CASE(nullpointer15); // #3560 (fp: return p ? f(*p) : f(0))
|
TEST_CASE(nullpointer15); // #3560 (fp: return p ? f(*p) : f(0))
|
||||||
|
TEST_CASE(nullpointer16); // #3591
|
||||||
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
|
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
|
||||||
TEST_CASE(nullConstantDereference); // Dereference NULL constant
|
TEST_CASE(nullConstantDereference); // Dereference NULL constant
|
||||||
TEST_CASE(gcc_statement_expression); // Don't crash
|
TEST_CASE(gcc_statement_expression); // Don't crash
|
||||||
|
@ -1200,6 +1201,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nullpointer16() { // #3591
|
||||||
|
check("void foo() {\n"
|
||||||
|
" int *p = 0;\n"
|
||||||
|
" bar(&p);\n"
|
||||||
|
" *p = 0;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
// Check if pointer is null and the dereference it
|
// Check if pointer is null and the dereference it
|
||||||
void pointerCheckAndDeRef() {
|
void pointerCheckAndDeRef() {
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
|
Loading…
Reference in New Issue