Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Floating-point numbers can take on two classes of exceptional values; infinity and NaN (not-a-number). These values are returned as the result of exceptional or otherwise unresolvable floating point operations. (See also: FLP32-C. Prevent or detect domain and range errors in math mEath functions). Additionally, they can be directly input by a user by scanf or similar functions. Failure to detect and handle such values can result in undefined behavior.
NaN values are particularly problematic, as the expression NaN==NaN (for every possible value of NaN) returns false. Any comparisons made with NaN as one of the arguments returns false, and all arithmetic functions on NaNs simply propagate them through the code. Hence, a NaN entered in one location in the code and not properly handled could potentially cause problems in other, more distant sections.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

This rule appears in the Java Secure Coding Standard as FLP04-J. Check floating point inputs for exceptional values

References

Wiki Markup
\[[IEEE 754|AA. C References#IEEE 754 2006]\]
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\]
\[[IEEE 1003.1, 2004|AA. C References#IEEE 1003]\]