Modulo
The modulo operator provides the remainder when two operands of integer type are divided. Modulo operaitons are susceptible to division-by-zero errors.
Non-compliant Code Example
The following code can result in a divide-by-zero error during the modulo operation on the signed operands sl1 and sl2.
signed long sl1, sl2, result; result = sl1 % sl2;
Compliant Solution
The following compliant solution tests the suspect modulo operation to guarantee there is no possibility of a divide-by-zero error.
signed long sl1, sl2, result;
if (sl2 == 0) {
/* handle error condition */
}
result = sl1 % sl2;