testnullpointer.cpp: Add test for dereferencing returned NULL pointer (#2401)
This adds a regression test to make sure that directly dereferencing a returned NULL pointer issues a warning. This has been asked on Stack Overflow: https://stackoverflow.com/q/58981369 Cppcheck 1.89 does not warn for such a code, but 1.90 dev does. So it is a good idea to make sure it is detected in the future too I guess.
This commit is contained in:
parent
8af2ee968e
commit
fd900ab8b2
|
@ -2062,6 +2062,14 @@ private:
|
||||||
" typeof(*NULL) y;\n"
|
" typeof(*NULL) y;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("int * f() {\n"
|
||||||
|
" return NULL;\n"
|
||||||
|
"}\n"
|
||||||
|
"int main() {\n"
|
||||||
|
" return *f();\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f()\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void gcc_statement_expression() {
|
void gcc_statement_expression() {
|
||||||
|
|
Loading…
Reference in New Issue