Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The solution is to provide the open and close parentheses following the geteuid token so that the function is properly invoked.:

Code Block
bgColor#ccccff
langc
/* 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
bgColor#ccccff
langc
/* 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
bgColor#FFcccc
langc
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
bgColor#ccccff
langc
int do_xyz(void); 
 
if (do_xyz()) { 
  /* handle error */ 
} 

...

Tool

Version

Checker

Description

Coverity

Include Page
Coverity_V
Coverity_V

BAD_COMPARE

Can detect the specific instance where the address of a function is compared against 0, such as in the case of
geteuid versus getuid() in the implementation-specific details.

GCC
Include Page
GCC_V
GCC_V
 

Can detect violations of this recommendation when the -Wall flag is used.

Klocwork

Include Page
Klocwork_V
Klocwork_V

EFFECT

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V
  

...