Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This compliant solution guarantees there is no possibility of signed overflow or divide-by-zero errors.

Code Block
bgColorccccff#ccccff
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
bgColorccccff#ccccff
signed int si1, result;

/* Initialize si1 */

if (si1 == INT_MIN) {
  /* handle error condition */
}
else
  result = -si1;
}

...