V2634. MISRA. Features from <fenv.h> should not be used.
This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.
This diagnostic rule is relevant only for C.
Avoid using functions or macros from the <fenv.h>
header file. In some cases, using the functionality of this file may result in unspecified or undefined behavior.
Below are some potential issues that can arise when working with <fenv.h>
.
Issue N1. The order in which floating-point exception flags are set when calling feraiseexcept
is not specified.
Issue N2. Calling fesetenv
and/or feupdateenv
with an argument that was not obtained via feholdexcept
/ fegetenv
, or by expanding the FE_DFL_ENV
macro leads to undefined behavior.
Issue N3. Some implementations of functions from the <math.h>
header support rounding floating-point numbers only to the nearest representable value (FE_TONEAREST
). If a different rounding mode is set, the result of calling such functions can be unpredictable.
The examples where the analyzer issues warnings:
void clear_overflow_status()
{
feclearexcept(FE_OVERFLOW);
}
void change_rounding_direction()
{
fesetround(FE_DOWNWARD);
}
double some_computation(void)
{
int r = feraiseexcept(FE_OVERFLOW | FE_INEXACT);
printf("feraiseexcept() %s\n", (r?"fails":"succeeds"));
return 0.0;
}
This diagnostic is classified as:
|