Avoid in-band error indicators while designing interfaces. This practice is commonly used by C library functions but is not recommended. One example from the C standard of a troublesome in-band error indicator is EOF
. (See rules FIO34-C. Use int to capture the return value of character IO functions and FIO35-C. Use feof() and ferror() to detect end-of-file and file errors when sizeof(int) == sizeof(char).) Another problematic use of in-band error indicators from the C standard involving the size_t
and time_t
types is described by rule MSC31-C. Ensure that return values are compared against the proper type.
Noncompliant Code Example (sprintf()
)
This specific noncompliant code example is from the Linux Kernel Mailing List archive site, although similar examples are common.
...