...
This noncompliant code example calls puts()
and fails to check whether a write error occurs.
Code Block | ||||
---|---|---|---|---|
| ||||
puts("foo"); |
However, puts()
can fail and return EOF
.
...
This compliant solution checks to make sure no output error occurred. (See recommendation FIO04-C. Detect and handle input and output errors.)
Code Block | ||||
---|---|---|---|---|
| ||||
if (puts("foo") == EOF) { /* Handle error */ } |
...
EXP12-EX2: If a function cannot fail or if the return value cannot signify an error condition, the return value may be ignored. Such functions should be added to a white list when automatic checkers are used.
Code Block | ||||
---|---|---|---|---|
| ||||
strcpy(dst, src); |
Risk Assessment
...