Fix #3256 (Null pointer dereference not detected)
http://sourceforge.net/apps/trac/cppcheck/ticket/3256 It is now detected if --inconclusive command line argument is given (the argument is unofficial currently)
This commit is contained in:
parent
950460c0a7
commit
5e0e2c4782
|
@ -817,9 +817,14 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
if (Token::simpleMatch(tok2, ") ;") &&
|
if (Token::simpleMatch(tok2, ") ;") &&
|
||||||
(Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") ||
|
(Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") ||
|
||||||
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) {
|
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) {
|
||||||
// noreturn function?
|
if (!_settings->inconclusive) {
|
||||||
if (tok2->strAt(2) == "}")
|
// noreturn function?
|
||||||
break;
|
// If inside null pointer check we unknown function call, we must
|
||||||
|
// assume that it can terminate the program and possible null pointer
|
||||||
|
// error wont ever happen.
|
||||||
|
if (tok2->strAt(2) == "}")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// init function (global variables)
|
// init function (global variables)
|
||||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
|
@ -1176,6 +1176,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo(char *p) {\n"
|
||||||
|
" if (!p) {\n"
|
||||||
|
" abort();\n"
|
||||||
|
" }\n"
|
||||||
|
" *p = 0;\n"
|
||||||
|
"}\n", true);
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 2\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (!p) {\n"
|
" if (!p) {\n"
|
||||||
" (*bail)();\n"
|
" (*bail)();\n"
|
||||||
|
|
Loading…
Reference in New Issue