2 typedef __UINT32_TYPE__
uint32_t;
4 typedef __UINT32_TYPE__
unsigned;
26 struct bitfield bfval
;
29 __attribute__ ((noinline
, noclone
)) uint32_t
30 partial_read_le32 (union bf_or_uint32 in
)
32 return in
.bfval
.f0
| (in
.bfval
.f1
<< 8)
33 | (in
.bfval
.f2
<< 16) | (in
.bfval
.f3
<< 24);
36 __attribute__ ((noinline
, noclone
)) uint32_t
37 partial_read_be32 (union bf_or_uint32 in
)
39 return in
.bfval
.f3
| (in
.bfval
.f2
<< 8)
40 | (in
.bfval
.f1
<< 16) | (in
.bfval
.f0
<< 24);
43 __attribute__ ((noinline
, noclone
)) uint32_t
44 fake_read_le32 (char *x
, char *y
)
46 unsigned char c0
, c1
, c2
, c3
;
53 return c0
| c1
<< 8 | c2
<< 16 | c3
<< 24;
56 __attribute__ ((noinline
, noclone
)) uint32_t
57 fake_read_be32 (char *x
, char *y
)
59 unsigned char c0
, c1
, c2
, c3
;
66 return c3
| c2
<< 8 | c1
<< 16 | c0
<< 24;
69 __attribute__ ((noinline
, noclone
)) uint32_t
70 incorrect_read_le32 (char *x
, char *y
)
72 unsigned char c0
, c1
, c2
, c3
;
79 return c0
| c1
<< 8 | c2
<< 16 | c3
<< 24;
82 __attribute__ ((noinline
, noclone
)) uint32_t
83 incorrect_read_be32 (char *x
, char *y
)
85 unsigned char c0
, c1
, c2
, c3
;
92 return c3
| c2
<< 8 | c1
<< 16 | c0
<< 24;
98 union bf_or_uint32 bfin
;
100 char cin
[] = { 0x83, 0x85, 0x87, 0x89 };
102 if (sizeof (uint32_t) * __CHAR_BIT__
!= 32)
104 bfin
.inval
= (struct ok
) { 0x83, 0x85, 0x87, 0x89 };
105 out
= partial_read_le32 (bfin
);
106 /* Test what bswap would do if its check are not strict enough instead of
107 what is the expected result as there is too many possible results with
109 if (out
== 0x89878583)
111 bfin
.inval
= (struct ok
) { 0x83, 0x85, 0x87, 0x89 };
112 out
= partial_read_be32 (bfin
);
113 /* Test what bswap would do if its check are not strict enough instead of
114 what is the expected result as there is too many possible results with
116 if (out
== 0x83858789)
118 out
= fake_read_le32 (cin
, &cin
[2]);
119 if (out
!= 0x89018583)
122 out
= fake_read_be32 (cin
, &cin
[2]);
123 if (out
!= 0x83850189)
126 out
= incorrect_read_le32 (cin
, &cin
[2]);
127 if (out
!= 0x89878583)
130 out
= incorrect_read_be32 (cin
, &cin
[2]);
131 if (out
!= 0x83858789)