...
This compliant solution guarantees there is no possibility of signed overflow or divide-by-zero errors.
| Code Block | ||
|---|---|---|
| ||
signed long sl1, sl2, result;
/* Initialize sl1 and sl2 */
if ( (sl2 == 0) || ( (sl1 == LONG_MIN) && (sl2 == -1) ) ) {
/* handle error condition */
}
else {
result = sl1 / sl2;
}
|
...
This compliant solution tests the suspect negation operation to guarantee there is no possibility of signed overflow.
| Code Block | ||
|---|---|---|
| ||
signed int si1, result;
/* Initialize si1 */
if (si1 == INT_MIN) {
/* handle error condition */
}
else
result = -si1;
}
|
...