Bug 480126 - Build failure on Raspberry Pi 5 / OS 6.1.0-rpi7-rpi-v8
[valgrind.git] / memcheck / tests / metadata.c
blobc09aa6ab241af6b558f579e0e1972446b280f259
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "../memcheck.h"
6 /* Program demonstrating copying of metadata in memcheck. */
8 int main ( void )
10 int* a = malloc(10 * sizeof(int));
11 int* b = malloc(10 * sizeof(int));
12 int* v = malloc(10 * sizeof(int));
13 int i, sum, res;
15 for (i = 0; i < 10; i++) {
16 if (i != 5)
17 a[i] = i;
20 /* a[0 .. 4] and [6 .. 9] are defined, [5] is undefined. */
21 for (i = 0; i < 10; i++)
22 b[i] = 0;
24 /* b[0 .. 9] is defined. */
26 /* Get metadata for a and put it in v. */
27 res = VALGRIND_GET_VBITS(a, v, 10*sizeof(int) );
28 printf("result of GET is %d (1 for success)\n", res);
30 for (i = 0; i < 10; i++)
31 printf("%d 0x%08x\n", i, v[i]);
33 /* and copy to b. */
34 res = VALGRIND_SET_VBITS(b, v, 10*sizeof(int) );
35 printf("result of SET is %d (1 for success)\n", res);
37 /* Now we should have that b[5] is undefined since a[5] is
38 undefined. */
39 sum = 100;
40 for (i = 0; i < 10; i++)
41 sum += b[i];
43 /* V should yelp at this point, that sum is undefined. */
44 if (sum == 0)
45 printf("sum == 0\n");
46 else
47 printf("sum != 0\n");
49 return 0;