Various minor fixes for compiler/linter (other then splint itself) warnings.
[splint-patched.git] / test / union.c
blob31418c6e117a67c9ac662c8814cef81f36022ebf
1 typedef union _ut
3 int x;
4 int y;
5 int *ox;
6 /*@dependent@*/ int *dx;
7 struct { int a; int b; int *ip; } st;
8 } *ut;
10 extern /*@only@*/ /*@out@*/ void *smalloc (size_t);
12 ut ut_create1 (/*@unused@*/ int a)
14 ut u = (ut) smalloc (sizeof (*u));
16 return u; /* 1. Returned union u contains no defined field */
19 ut ut_create2 (int a)
21 ut u = (ut) smalloc (sizeof (*u));
23 u->x = a;
24 return u;
27 ut ut_create3 (int a)
29 ut u = (ut) smalloc (sizeof (*u));
31 u->x = a;
32 u->y = a;
33 return u; /* [Not anymore. Returned union u has 2 defined fields: x, y */
36 ut ut_create4 (int *t)
38 ut u = (ut) smalloc (sizeof (*u));
40 u->ox = t; /* 2. Implicitly temp storage t assigned to implicitly only */
41 return u;
44 ut ut_create5 (int *t)
46 ut u = (ut) smalloc (sizeof (*u));
48 u->dx = t; /* 3. Implicitly temp storage t assigned to dependent: u->dx = t */
49 return u;
52 ut ut_create6 (void)
54 ut u = (ut) smalloc (sizeof (*u));
56 u->st.a = 3;
57 return u; /* 4. Returned storage u->st contains 2 undefined fields: b, ip */
60 ut ut_create7 (int *p)
62 ut u = (ut) smalloc (sizeof (*u));
64 u->st.a = 3;
65 u->st.b = 4;
66 u->st.ip = p; /* 5. Implicitly temp storage p assigned to implicitly only */
67 return u;
70 void ut_mangle1 (ut u)
72 free (u->ox);
73 } /* 6. Released storage u->ox reachable from parameter */
75 void ut_mangle2 (ut u)
77 free (u->st.ip);
78 } /* 7. Released storage u->st.ip reachable from parameter */
80 void ut_mangle3 (ut u)
82 free (u->st.ip);
83 u->x = 3; /* This one's a toughy... */
84 } /* 8. Released storage u->st.ip reachable from parameter */