...
| Code Block | ||||
|---|---|---|---|---|
| ||||
signed long s_a;
signed long s_b;
signed long result;
void func(void) {
/* initializeInitialize s_a and s_b */
result = s_a % s_b;
/* ... */
} |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <limits.h>
signed long s_a;
signed long result;
void func(void) {
if ((si1 < 0) || (si2 < 0) ||
(si2 >= UWIDTH(signed long, ULONG_MAX)) ||
(si1 > (INT_MAX >> si2))) {
/* handleHandle error condition */
} else {
sresult = si1 << si2;
}
/* ... */
}
|
...
The C Standard defines the behavior of arithmetic on atomic signed integer types to use two's complement representation with silent wraparound on overflow; there are no undefined results. However, although defined, these results may be unexpected and therefore carry similar risks to unsigned integer wrapping (see INT30-C. Ensure that unsigned integer operations do not wrap). Consequently, signed integer overflow of atomic integer types should also be prevented or detected.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
INT32-C | highHigh | likelyLikely | highHigh | P9 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Coverity | 6.5 | TAINTED_STATIC | Fully Implemented | ||||||
5.0 | Can detect violations of this rule with CERT C Rule Pack. Specifically, it checks to ensure that the operand of a unary negation is compared to the type's minimum value immediately before the operation | ||||||||
| 43 D | Partially implemented | |||||||
| PRQA QA-C |
| 0278 | Fully implemented |
...