Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Dir-4.15

In this section:
Synopsis

(Required) Evaluation of floating-point expressions shall not lead to the undetected generation of infinities and NaNs.

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

Unhandled infinite or NaN in floating-point expressions found.

Coding standards
MISRA C:2012 Dir-4.15

(Required) Evaluation of floating-point expressions shall not lead to the undetected generation of infinities and NaNs.

Code examples

The following code example fails the check and will give a warning:

#include <math.h>

extern double get_result(); /* Return value may be infinite or valid data */
extern void use_result( double c ); /* Not protected against NANs or or infinities */

void f( void )
{
 double a = get_result();
 use_result( a ); /* Non-compliant - c not tested */
}

The following code example passes the check and will not give a warning about this issue:

#include <math.h>

extern double get_result(); /* Return value may be infinite or valid data */
extern void use_result( double c ); /* Not protected against NANs or or infinities */

void f( void )
{
 double a = get_result();
 if (isfinite(a) && !isnan(a))
 {
    use_result( a ); /* Compliant - tested */
 }
}