...
Function | Bounds-checking |
---|---|
acos(x), asin(x) | -1 <= x && x <= 1 |
atan2 | x != 0 || y != 0 |
log, log10 | x >= 0 |
pow(x, y) | x != 0 || y > 0 |
sqrt(x) | x >= 0 |
The calling function should take alternative action if these bounds are violated.
acos
...
, asin
...
Non-Compliant Example
The following code may produce a domain error if the argument is not in the range -1, +1.
...
Code Block |
---|
float x, y, result; if( fpclassify(x) == FP_ZERO && fpclassify(y) == FP_ZERO){ /* handle domain error */ } result = atan2(y, x); |
log
...
, log10
...
Non-Compliant Example
The following code may produce a domain error if x is negative and a range error if x is zero.
...
Code Block |
---|
float x, y, result; if(fpclassify(x) == FP_ZERO && islessequal(y, 0)){ /* handle domain error condition */ } result = pow(x, y); |
Sqrt
...
Non-Compliant Solution
The following code may produce a domain error if x is negative.
...
Code Block |
---|
float x, result; if(isless(x, 0)){ /* handle domain error */ } result = sqrt(x); |
Priority: P6 Level: L2
Component | Value |
---|---|
Severity | 1 (high) |
Likelihood | 2 (probable) |
Remediation cost | 2 (high) |
References
- ISO/IEC 9899-1999 7.12 Mathematics <math.h>
- Plum 91 Topic: 2.10 conv - conversions and overflow