MISRA C:2012 Rule 22.8
The value of errno
shall be set to zero prior to a call to an
errno
-setting-function
Description
Rule Definition
The value of errno
shall be set to zero prior to a
call to an errno
-setting-function.
This rule comes from MISRA C™: 2012 Amendment 1.
Rationale
An errno
-setting function sets errno
to nonzero values to indicate error conditions.
If you do not set errno
to zero before calling an errno
-setting function,a nonzero value of errno
might be left over from a previous call to an errno
-setting function. Using errno
to check errors can then lead you to falsely conclude that an error occurred from the most recent call.
errno
is set to 0 at program startup but is not automatically reset after an error occurs. You must explicitly set errno
to 0 when required.
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 |