...
This noncompliant code example can result in a divide-by-zero error during the division of the signed operands s_a and s_b. It can also result in a signed integer overflow error on twos-complement platforms. The IAx86-32 architecture, for example, requires that both conditions result in a fault, which can easily result in a denial-of-service attack.
...
This noncompliant code example can result in a divide-by-zero error during the modulo operation on the signed operands s_a and s_b. Furthermore, many hardware platforms implement modulo as part of the division operator, which can overflow. Overflow can occur during a modulo operation when the dividend is equal to the minimum (negative) value for the signed integer type and the divisor is equal to −1. This occurs despite that occurs even though the result of such a modulo operation should theoretically be is mathematically 0.
| Code Block | ||||
|---|---|---|---|---|
| ||||
void func(signed long s_a, signed long s_b) {
signed long result = s_a % s_b;
/* ... */
} |
...