Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rdemeter
GitHub Repository: rdemeter/so
Path: blob/master/lab4/mcheck_test.c
221 views
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
5
int main(void)
6
{
7
int *v1;
8
9
v1 = (int *) malloc(5 * sizeof(*v1));
10
if (NULL == v1) {
11
perror("malloc");
12
exit (EXIT_FAILURE);
13
}
14
/* overflow */
15
v1[6] = 100;
16
17
free(v1);
18
19
/* write after free */
20
v1[6] = 100;
21
22
/* reallocate v1 */
23
v1 = malloc(10 * sizeof(int));
24
if (NULL == v1) {
25
perror("malloc");
26
exit (EXIT_FAILURE);
27
}
28
29
return 0;
30
}
31
32