1 
2 #include <stdlib.h>
3 #include <stdio.h>
4 
5 #include "../memcheck.h"
6 
7 /* This test checks that VALGRIND_CHECK_MEM_IS_DEFINED correctly
8    reports two errors when presented with a buffer which contains both
9    undefined data and some out of range component(s), and the
10    undefined data appears before the out of range components.  Should
11    report 5 errors in total: the first test should report 2, the rest
12    1 each. */
13 
main(void)14 int main ( void )
15 {
16    char* a;
17 
18    fprintf(stderr, "\n---- part defined, address error at end ----\n\n");
19    a = malloc(8);
20    a[0] = a[1] = a[2] = a[3] = a[6] = a[7] = 'x';
21    (void) VALGRIND_CHECK_MEM_IS_DEFINED(a, 9);
22    free(a);
23 
24    fprintf(stderr, "\n---- part defined, address error at start ----\n\n");
25    a = malloc(8);
26    a[0] = a[1] = a[2] = a[3] = a[6] = a[7] = 'x';
27    (void) VALGRIND_CHECK_MEM_IS_DEFINED(a-1, 9);
28    free(a);
29 
30    fprintf(stderr, "\n---- fully defined, address error at end ----\n\n");
31    a = malloc(8);
32    a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = 'x';
33    (void) VALGRIND_CHECK_MEM_IS_DEFINED(a, 9);
34    free(a);
35 
36    fprintf(stderr, "\n---- fully defined, address error at start ----\n\n");
37    a = malloc(8);
38    a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = 'x';
39    (void) VALGRIND_CHECK_MEM_IS_DEFINED(a-1, 9);
40    free(a);
41 
42    return 0;
43 }
44