MISRAC2012-Rule-22.10
In this section:
Synopsis
(Required) The value of errno shall only be tested when the last function to be called was an errno-setting-function.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
errno is tested after a call to function that is not an errno-setting-function.
Coding standards
- MISRA C:2012 Rule-22.10
(Required) The value of errno shall only be tested when the last function to be called an errno-setting-function
Code examples
The following code example fails the check and will give a warning:
#include<mc3_types.h>
void f ( void )
{
float64_t f64;
errno = 0;
f64 = atof ( "A.12" );
if ( 0 == errno ) /* Non-compliant */
{
/* f64 may not have a valid value in here.
*/
}
}
The following code example passes the check and will not give a warning about this issue:
#include<mc3_types.h>
void f ( void )
{
float64_t f64;
errno = 0;
f64 = strtod ( "A.12", NULL );
if ( 0 == errno ) /* Compliant */
{
/* f64 will have a valid value in here. */
}
}