...
| Code Block | ||||
|---|---|---|---|---|
| ||||
void func(unsigned int ui_a, unsigned int ui_b) {
unsigned int usum = ui_a + ui_b;
if (usum < ui_a) {
/* Handle error */
}
/* ... */
} |
Compliant Solution (C23, Checked Integers)
This compliant solution uses the new-to-C23 checked integer arithmetic to safely perform integer addition:
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdckdint.h>
void func(unsigned int ui_a, unsigned int ui_b) {
unsigned int usum;
if (ckd_add(&usum, ui_a, ui_b)) {
/* Handle error */
}
/* ... */
} |
| Anchor | ||||
|---|---|---|---|---|
|
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
INT30-C | High | Likely | High | P9 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| integer-overflow | Fully checked | ||||||
| Axivion Bauhaus Suite |
| CertC-INT30 | Implemented | ||||||
| CodeSonar |
| ALLOC.SIZE.ADDOFLOW | Addition overflow of allocation size | ||||||
| Compass/ROSE | Can detect violations of this rule by ensuring that operations are checked for overflow before being performed (Be mindful of exception INT30-EX2 because it excuses many operations from requiring validation, including all the operations that would validate a potentially dangerous operation. For instance, adding two | ||||||||
| Coverity |
| INTEGER_OVERFLOW | Implemented | ||||||
| Cppcheck Premium |
| premium-cert-int30-c | |||||||
| Helix QAC |
| C2910, C3383, C3384, C3385, C3386 C++2910 DF2911, DF2912, DF2913, | |||||||
| Klocwork |
| NUM.OVERFLOW | |||||||
| LDRA tool suite |
| 493 S, 494 S | Partially implemented | ||||||
| Parasoft C/C++test |
| CERT_C-INT30-a | Avoid wraparounds when performing arithmetic integer operations | ||||||
| Polyspace Bug Finder |
| CERT C: Rule INT30-C | Checks for:
Rule partially covered. | ||||||
| PVS-Studio |
| V658, V1012, V1028, V5005, V5011 | |||||||
| TrustInSoft Analyzer |
| unsigned overflow | Exhaustively verified. |
...