MISRAC2012-Rule-21.18_a
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
High/Medium

Full description
A call to a function in <string.h> 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>
char buf1[5];
char buf2[10];
void f(void)
{
if (memcmp(buf1, buf2, 6) == 0) /* Non-compliant */
{
}
}
The following code example passes the check and will not give a warning about this issue:
#include <string.h>
char buf1[5];
char buf2[10];
void f(void)
{
if (memcmp(buf1, buf2, 5) == 0) /* Compliant */
{
}
}