Versions Compared

Key

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

Many functions return useful values whether or not the function has side effects. In most cases, this value is used to signify whether the function successfully completed its task or if some error occurred . (See see ERR02-C. Avoid in-band error indicators). ) Other times, the value is the result of some computation and is an integral part of the function's API.

...

This recommendation encompasses void MEM32ERR33-C. Detect and handle memory allocation errors, VOID FIO04-C. Detect and handle input and output errors, and void FIO34-C. Use int to capture the return value of character IO functions that might be used to check for end of file.standard library errors.

Noncompliant Code Example

...

This compliant solution checks to make sure no output error occurred . (See VOID FIO04see ERR33-C. Detect and handle input and output standard library errors).)

Code Block
bgColor#ccccff
langc
if (puts("foo") == EOF) {
  /* Handle error */
}

...

Tool

Version

Checker

Description

CodeSonar
Include Page
CodeSonar_V
CodeSonar_V
LANG.FUNCS.IRVIgnored Return Valuereturn value

Compass/ROSE

 

 

 

Coverity

Include Page
Coverity_V
Coverity_V

CHECKED_RETURN

Finds inconsistencies in how function call return values are handled. Coverity Prevent cannot discover all violations of this recommendation, so further verification is necessary

Cppcheck 
Include Page
Cppcheck_V
Cppcheck_V
leakReturnValNotUsed, ignoredReturnValue

Return value of memory allocation function is not used.

Ignored return value from function when configuration says it must be used. See the chapter "Library configuration" in the cppcheck manual.

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.EXP12

Fully implemented

Klocwork

Include Page
Klocwork_V
Klocwork_V

SV.RVT.RETVAL_NOTTESTED

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V

382 S

Fully implemented

PRQA QA-C
Include Page
PRQA QA-C_v
PRQA QA-C_v
3200Fully implemented

Splint

Include Page
Splint_V
Splint_V

 

 

...