MISRAC2012-Rule-21.18_b
In this section:
Synopsis
(Mandatory) The size_t argument passed to any function in <string.h> shall have an appropriate value
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
A call to memchr causes a buffer overrun.
Coding standards
- CERT ARR38-C
Guarantee that library functions do not form invalid pointers
- MISRA C:2012 Rule-21.18
(Mandatory) The size_t argument passed to any functions in <string.> shall have an appropriate value
Code examples
The following code example fails the check and will give a warning:
#include <string.h>
void f() {
char s[] = "Hello";
memchr(s, 'H', 10);
}
The following code example passes the check and will not give a warning about this issue:
#include <string.h>
void f() {
char s[] = "Hello";
memchr(s, 'H', 10);
}