This commit is contained in:
PKEuS 2012-02-13 19:46:45 +01:00
parent df0cb89a40
commit 2e13a51d08
2 changed files with 11 additions and 1 deletions

View File

@ -1208,7 +1208,7 @@ private:
if (Token::Match(tok.previous(), "[;{}=] %var% = 0 ;"))
setnull(checks, tok.varId());
else if (!deref &&
!tok.previous()->isOp() && !tok.previous()->isAssignmentOp() &&
(!tok.previous()->isOp() || tok.previous()->str() == "&") && !tok.previous()->isAssignmentOp() &&
(!tok.next()->isOp() || tok.next()->str() == ">>"))
bailOutVar(checks, tok.varId()); // If its possible that the pointers value changes, bail out.
}

View File

@ -49,6 +49,7 @@ private:
TEST_CASE(nullpointer13); // ticket #1708
TEST_CASE(nullpointer14);
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(nullConstantDereference); // Dereference NULL constant
TEST_CASE(gcc_statement_expression); // Don't crash
@ -1200,6 +1201,15 @@ private:
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
void pointerCheckAndDeRef() {
check("void foo(char *p) {\n"