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.
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.
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