...
The solution is to provide the open and close parentheses following the geteuid
token so that the function is properly invoked.:
Code Block | ||||
---|---|---|---|---|
| ||||
/* First the options that are only allowed for root */ if (getuid() == 0 || geteuid() != 0) { /* ... */ } |
...
A function pointer can be compared to a null function pointer of the same type.:
Code Block | ||||
---|---|---|---|---|
| ||||
/* First the options that are only allowed for root */ if (getuid == (uid_t(*)(void))0 || geteuid != (uid_t(*)(void))0) { /* ... */ } |
...
In this noncompliant code example, the function pointer do_xyz
is implicitly compared unequal to 0.:
Code Block | ||||
---|---|---|---|---|
| ||||
int do_xyz(void); if (do_xyz) { /* handle error */ } |
...
In this compliant solution, the function do_xyz()
is invoked and the return value is compared to 0.:
Code Block | ||||
---|---|---|---|---|
| ||||
int do_xyz(void); if (do_xyz()) { /* handle error */ } |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| BAD_COMPARE | Can detect the specific instance where the address of a function is compared against 0, such as in the case of | |||||||
GCC |
| Can detect violations of this recommendation when the | |||||||
| EFFECT | ||||||||
|
...