MISRAC++2023-8.7.1_b
In this section:
Synopsis
(Required) Pointer arithmetic shall not form an invalid pointer
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
This check validates arithmetic operations. In order to not cause too many false positives, it takes a conservative approach and will not give a message if it is not obvious to the checker that it is a violation.
Coding standards
- MISRA C++ 2008 5-0-6
(Required) An implicit integral or floating-point conversion shall not reduce the size of the underlying type.
Code examples
The following code example fails the check and will give a warning:
void example() {
int a[333] = { };
int* p = a + 334; // Not compliant
}
The following code example passes the check and will not give a warning about this issue:
void example() {
int a[222] = { };
int* p = a + 222; // Compliant (but still an invalid pointer)
}