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

Full description
This validates parameters in standard library calls.
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:
#include <cstring>
void example() {
unsigned char buf[] = { 1, 2, 3 };
std::memchr( buf, 65, 5 ); // Non-compliant
}
The following code example passes the check and will not give a warning about this issue:
#include <cstring>
void example() {
unsigned char buf[] = { 1, 2, 3 };
std::memchr( buf, 65, 3 ); // Compliant
}