...
Many implementations of the stdio
package adjust their behavior slightly if stdout
is a terminal. To make the determination, these implementations perform some operation that fails (with ENOTTY
) if stdout
is not a terminal. Although the output operation goes on to complete successfully, errno
still contains ENOTTY
. This behavior can be mildly confusing, but it is not strictly incorrect because it is only meaningful for a program to inspect the contents of errno
after an error has been reported. More precisely, errno
is only meaningful after a library function that sets errno
on error has returned an error code.
Code Block | ||||
---|---|---|---|---|
| ||||
errno = 0;
printf("This\n");
printf("is\n");
printf("a\n");
printf("test.\n");
if (errno != 0) {
fprintf(stderr, "printf failed: %s\n", strerror(errno));
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
printf("This\n");
printf("is\n");
printf("a\n");
printf("test.\n");
if (ferror(stdout)) {
fprintf(stderr, "printf failed\n");
}
|
...
Tool | Version | Checker | Description | section||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
| stlibuse section | Fully Implementedimplemented |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
CERT C++ Secure Coding Standard: ERR01-CPP. Use ferror() rather than errno to check for FILE stream errors
ISO/IEC 9899:1999 Section 2011 Section 6.3.1.1, "Boolean, characters, and integers," Section 7.1.4, "Use of library functions," and Section 7.921.10.3, "The ferror
function"
...