Comparing a function pointer to a value that is not a null function pointer of the same type shall be diagnosed because this typically indicates programmer error and can result in unexpected behavior. Implicit comparisons shall be diagnosed as well.
Noncompliant Code Example
In this noncompliant code example, the function pointers getuid
and geteuid
are compared to 0.
...
Code Block | ||
---|---|---|
| ||
/* First the options that are only allowed for root */ if (getuid() == 0 || geteuid() != 0) { /* ... */ } |
Compliant Code Example
A function pointer can be compared to a null function pointer of the same type.
...
Code Block | ||
---|---|---|
| ||
int do_xyz(void); if (do_xyz) { /* handle error */ } |
Compliant Solution
In this compliant solution, the function do_xyz()
is invoked and the return value is compared to 0.
...