MISRAC2012-Rule-1.3_u
In this section:
Synopsis
(Required) There shall be no occurrence of undefined or critical unspecified behavior.
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
A call to memset causes a buffer overrun.
Coding standards
- CWE 676
Use of Potentially Dangerous Function
- CWE 122
Heap-based Buffer Overflow
- CWE 121
Stack-based Buffer Overflow
- CWE 119
Improper Restriction of Operations within the Bounds of a Memory Buffer
- CWE 805
Buffer Access with Incorrect Length Value
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
void example(void) {
char *a = malloc(sizeof(char) * 20);
memset(a, 'a', 21);
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
void example(void) {
char *a = malloc(sizeof(char) * 20);
memset(a, 'a', 10);
}