...
To provide a true (never negative) modulo operation, use the imod() ("integer modulo") inline function:. The number of operations it performs can be reduced to one in the case of C99.
| Code Block | ||
|---|---|---|
| ||
/* modulo function giving non-negative result */
inline int imod(int i, int j) {
if (__STDC_VERSION__ >= 199901L)
return i % j;
else
return (i % j) < 0 ? (i % j) + j : i % j;
}
|
The if statement condition is a constant and will be optimized away. This allows the compiler to check the syntax of the entire function, which will not happen if a #if preprocessing directive is used.
Risk Assessment
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
INT10-A | 1 (low) | 1 (unlikely) | 2 (medium) | P2 | L3 |
...