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 ERR02-A. Avoid in-band error indicators). Other times, this value is the result of some computation and is a necessary output.

...

All expression statements, such as function calls with an ignored value, are implicitly cast to void. Since a return value often contains important information about possible errors it should always be checked, otherwise the cast should be made explicit to signify programmer intent. If a function returns no meaningful value, it should be declared with return type void.

...

Code Block
bgColor#ffcccc
puts("foo");

However, puts() can fail and returns EOF is it does. If the output were determined to be critical, then the return value should have been checked.

Compliant Solution

This compliant solution checks to make sure no output error occurred (see FIO04-A. Detect and handle input and output errors).

...

Code Block
bgColor#ccccff
(void) strcpy(dst, src);

Risk Assessment

...