Errno not checked
errno
is not checked for error conditions
following function call
Description
This defect occurs when
you call a function that sets errno
to indicate
error conditions, but do not check errno
after
the call. For these functions, checking errno
is
the only reliable way to determine
if an error occurred.
Functions that set errno
on errors include:
fgetwc
,strtol
, andwcstol
.For a comprehensive list of functions, see documentation about errno.
POSIX®
errno
-setting functions such asencrypt
andsetkey
.
Risk
To see if the function call completed without errors, check errno
for
error values.
The return values of these errno
-setting
functions do not indicate errors. The return value can be one of the
following:
void
Even if an error occurs, the return value can be the same as the value from a successful call. Such return values are called in-band error indicators.
You can determine if an error occurred only by checking errno
.
For instance, strtol
converts a string to
a long integer and returns the integer. If the result of conversion
overflows, the function returns LONG_MAX
and sets errno
to ERANGE
.
However, the function can also return LONG_MAX
from
a successful conversion. Only by
checking errno
can you distinguish between an error
and a successful
conversion.
Fix
Before calling the function, set errno
to
zero.
After the function call, to see if an error occurred, compare errno
to
zero. Alternatively, compare errno
to known error
indicator values. For instance, strtol
sets errno
to ERANGE
to
indicate errors.
The error message in the Polyspace® result shows the error indicator value that you can compare to.
Examples
Result Information
Group: Security |
Language: C | C++ |
Default: Off |
Command-Line Syntax: ERRNO_NOT_CHECKED |
Impact: Medium |
Version History
Introduced in R2017a
See Also
Find defects (-checkers)
| Returned value of a sensitive function not checked
| Errno not reset
| Misuse of errno
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)