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 | ||||
---|---|---|---|---|
| ||||
if (puts("foo") == EOF) { /* Handle error */ } |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
CodeSonar |
| LANG.FUNCS.IRV | Ignored Return Valuereturn value | ||||||
|
|
| |||||||
| 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 |
| 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. | ||||||
| CC2.EXP12 | Fully implemented | |||||||
| SV.RVT.RETVAL_NOTTESTED |
| |||||||
| 382 S | Fully implemented | |||||||
PRQA QA-C |
| 3200 | Fully implemented | ||||||
|
|
|
...