Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: tweak atomic CS

...

Code Block
bgColor#ccccff
langc
#include <limits.h>
#include <stdatomic.h>
 
atomic_int i;
int si_a;

void func(void) {
  /* Initialize si_a, i */
  int si_b = atomic_load(&i);

  if (((si_b>0) && (si_a > (INT_MAX-si_b))) ||
      ((si_b<0) && (si_a < (INT_MIN-si_b)))) {
    /* Handle error condition */
  } else {
    atomic_fetch_addstore(&i, si_a + si_b);
  }

  /* ... */
}

Risk Assessment

...