detect when function pointer that is null is used

This commit is contained in:
Daniel Marjamäki 2010-01-23 09:15:30 +01:00
parent 7b986c831d
commit 037ecffc34
2 changed files with 11 additions and 0 deletions

View File

@ -1307,6 +1307,8 @@ private:
dereference(foundError, checks, &tok);
else if (Token::Match(tok.previous(), "return %var% [ %any% ]"))
dereference(foundError, checks, &tok);
else if (Token::Match(&tok, "%var% ("))
dereference(foundError, checks, &tok);
else
bailOutVar(checks, tok.varId());
}

View File

@ -990,6 +990,15 @@ private:
" int sz = sizeof((*(struct dummy *)0).x);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// function pointer..
checkNullPointer("void foo()\n"
"{\n"
" void (*f)();\n"
" f = 0;\n"
" f();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: f\n", errout.str());
}
void nullpointer7()