Versions Compared

Key

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

...

Code Block
bgColor#FFcccc
langc
atomic_int i;
int si1;

/* Initialize i, si1 */

atomic_fetch_add(&i, si1);

Compliant Solution

This compliant solution tests the operands to guarantee there is no possibility of signed overflow, regardless of representation. It loads the value stored in the atomic integer and tests for overflow as previously determined above.

Code Block
bgColor#ccccff
langc
atomic_int i;
int si1;

/* Initialize si1, i */

int si2 = atomic_load(&i);

if (((si2>0) && (si1 > (INT_MAX-si2)))
 || ((si2<0) && (si1 < (INT_MIN-si2)))) {
   /* handle error condition */
}
else {
  atomic_fetch_add(&i, si1);
}

Risk Assessment

...