...
Code Block |
---|
|
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 |
---|
|
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
...