Pointer arithmetic must be performed only on pointers that reference elements of array objects.
The C Standard, 6.5.6 7 [ISO/IEC 9899:20112024], states the following about pointer arithmetic:
...
Risk Assessment
Rule | Severity | Likelihood | Detectable | Remediation CostRepairable | Priority | Level |
|---|---|---|---|---|---|---|
ARR37-C | Medium | Probable | Yes | MediumNo | P8 | L2 |
Automated Detection
Tool | Version | Checker | Description | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| Supported indirectly via MISRA C:2004 Rule 17.4. | ||||||||||||||||||
| Axivion Bauhaus Suite |
| CertC-ARR37 | Fully implemented | |||||||||||||||||
| CodeSonar |
| LANG.MEM.BO | Buffer Overrun | |||||||||||||||||
| Compass/ROSE | ||||||||||||||||||||
| Coverity |
| ARRAY_VS_SINGLETON | Implemented | |||||||||||||||||
| Cppcheck Premium |
| premium-cert-arr37-c | ||||||||||||||||||
| Helix QAC |
| DF2930, DF2931, DF2932, DF2933 C++3705, C++3706, C++3707 | ||||||||||||||||||
| Klocwork |
| MISRACERT.ARR.PTR.ARITH | .2012||||||||||||||||||
| LDRA tool suite |
| 567 S | Partially implemented | |||||||||||||||||
| Parasoft C/C++test |
| CERT_C-ARR37-a | Pointer arithmetic shall not be applied to pointers that address variables of non-array type | |||||||||||||||||
| PC-lint Plus |
| 2662 | Partially supported | |||||||||||||||||
| Polyspace Bug Finder |
| CERT C: Rule ARR37-C | Checks for invalid assumptions about memory organization (rule partially covered) | PRQA QA-C | include | PRQA QA-C_v | PRQA QA-C_v | 2930, 2931, 2932, 2933 | PRQA QA-C++ | |||||||||||
| Include Page | cplusplus:PRQA QA-C++_V | cplusplus:PRQA QA-C++_V | 2930, 2931, 2932, 2933, 3705, 3706, 3707 | |||||||||||||||||
| RuleChecker |
| Supported indirectly via MISRA C:2004 Rule 17.4. |
...
| [Banahan 2003] | Section 5.3, "Pointers" Section 5.7, "Expressions Involving Pointers" |
| [ISO/IEC 9899:20112024] | 6.5.67, "Additive Operators" |
| [VU#162289] |
...