FPT-cmp-null
Synopsis
The address of a function is compared with NULL.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
The address of a function is compared with NULL. This is incorrect, because the address of a function is never NULL. If the intention was to call the function, but the parentheses were accidentally omitted, the application might behave unexpectedly because the address of the function is checked, not the return value. This means that the condition always holds, and any of the function's side-effects will not occur. If this was intentional, it is an unnecessary comparison, because a function address will never be NULL. If the function is declared but not defined, its address might fail to link if the function is called.
Coding standards
- CWE 480
Use of Incorrect Operator
Code examples
The following code example fails the check and will give a warning:
int foo() {
return 1;
}
int main(void) {
if (foo == 0) { /* foo, not foo() */
return 1;
}
return 0;
}
The following code example passes the check and will not give a warning about this issue:
int foo() {
return 0;
}
int main(void) {
if (foo() == 0) { /* foo() returns an int */
return 1;
}
return 0;
}