]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/exp-ptrcheck/tests/unaligned.c
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / exp-ptrcheck / tests / unaligned.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 int main ( void )
7 {
8    char* x = strdup("hello");
9    char c __attribute__((unused));
10    char c0[8], c1[8], c2[8], c3[8], c4[8];
11
12    // Each of these pointers has a different alignment
13    char** p0 = (char**)&c0[0];   char** p1 = (char**)&c1[1];
14    char** p2 = (char**)&c2[2];   char** p3 = (char**)&c3[3];
15    char** p4 = (char**)&c4[4];
16    *p0 = x;   *p1 = x;   *p2 = x;
17    *p3 = x;   *p4 = x;
18
19    // These 10 are ok
20    c = (*p0)[0];
21    c = (*p1)[0];
22    c = (*p2)[0];
23    c = (*p3)[0];
24    c = (*p4)[0];
25
26    c = (*p0)[5];
27    c = (*p1)[5];
28    c = (*p2)[5];
29    c = (*p3)[5];
30    c = (*p4)[5];
31
32    // These 10 are bad
33    c = (*p0)[-1];    // always word aligned, so det
34    c = (*p1)[-1];    // undet
35    c = (*p2)[-1];    // undet
36    c = (*p3)[-1];    // undet
37    c = (*p4)[-1];    // undet on 64-bit since not 64-bit aligned
38
39    c = (*p0)[6];     // always word aligned, so det
40    c = (*p1)[6];     // undet
41    c = (*p2)[6];     // undet
42    c = (*p3)[6];     // undet
43    c = (*p4)[6];     // undet on 64-bit since not 64-bit aligned
44
45    return 0;
46 }
47
48 /* What this program does: verifies that (unfortunately) if you store a
49    pointer misaligned, then the associated shadow value decays to Unknown,
50    and so when you retrieve the pointer later and dereference it, you
51    get no check :-( */