MISRA C:2012 Rule 22.9
The value of errno
shall be tested against zero after calling an
errno
-setting function
Description
Rule Definition
The value of errno
shall be tested against zero after
calling an errno
-setting function.1
This rule comes from MISRA C™: 2012 Amendment 1.
Rationale
If an error occurs during a call to an errno
-setting-function, the
function writes a nonzero value to errno
. Otherwise,
errno
is not modified.
When errno
is nonzero, the function return value is not likely to be
correct. Before using this return value, you must test errno
for nonzero
values.
Errno
-setting functions include:
ftell
,fgetpos
,fgetwc
and related functions.strtoimax
,strtol
and related functions.The wide-character equivalents such as
wcstoimax
andwcstol
are also covered.
Polyspace Implementation
Polyspace® reports a violation of this rule if your code calls an
errno
-setting function but does not test errno
against zero before calling another function.
Polyspace reports violations of this rule only for the functions that the C standard
specifies as errno
-setting function.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Resources |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2017a
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.