detect when function pointer that is null is used
This commit is contained in:
parent
7b986c831d
commit
037ecffc34
|
@ -1307,6 +1307,8 @@ private:
|
||||||
dereference(foundError, checks, &tok);
|
dereference(foundError, checks, &tok);
|
||||||
else if (Token::Match(tok.previous(), "return %var% [ %any% ]"))
|
else if (Token::Match(tok.previous(), "return %var% [ %any% ]"))
|
||||||
dereference(foundError, checks, &tok);
|
dereference(foundError, checks, &tok);
|
||||||
|
else if (Token::Match(&tok, "%var% ("))
|
||||||
|
dereference(foundError, checks, &tok);
|
||||||
else
|
else
|
||||||
bailOutVar(checks, tok.varId());
|
bailOutVar(checks, tok.varId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -990,6 +990,15 @@ private:
|
||||||
" int sz = sizeof((*(struct dummy *)0).x);\n"
|
" int sz = sizeof((*(struct dummy *)0).x);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void nullpointer7()
|
||||||
|
|
Loading…
Reference in New Issue