1 From fbb222c9bccb407750cea61e3bb6285cb8c1b330 Mon Sep 17 00:00:00 2001
2 From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
3 Date: Sun, 28 Jul 2019 13:48:50 +0900
4 Subject: [PATCH] axfer: test: fix invalid comparison of 64 bit storage in
7 In system V ABIs with ILP32 data model, bit shift for '1ul' can brings
8 undefined behaviour when the calculation result is over 32 bit width.
10 This commit fixes the bug.
12 Reported-by: Rolf Eike Beer <eike@sf-mail.de>
13 Reference: https://bugs.gentoo.org/681652
14 Reference: https://github.com/alsa-project/alsa-utils/issues/23
15 Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
16 Signed-off-by: Takashi Iwai <tiwai@suse.de>
18 axfer/test/container-test.c | 142 ++++++++++++++++++------------------
19 axfer/test/generator.c | 4 +-
20 axfer/test/mapper-test.c | 24 +++---
21 3 files changed, 85 insertions(+), 85 deletions(-)
23 diff --git a/axfer/test/container-test.c b/axfer/test/container-test.c
24 index 0e2e6e9..9b30ae3 100644
25 --- a/axfer/test/container-test.c
26 +++ b/axfer/test/container-test.c
27 @@ -172,82 +172,82 @@ int main(int argc, const char *argv[])
29 static const uint64_t sample_format_masks[] = {
30 [CONTAINER_FORMAT_RIFF_WAVE] =
31 - (1ul << SND_PCM_FORMAT_U8) |
32 - (1ul << SND_PCM_FORMAT_S16_LE) |
33 - (1ul << SND_PCM_FORMAT_S16_BE) |
34 - (1ul << SND_PCM_FORMAT_S24_LE) |
35 - (1ul << SND_PCM_FORMAT_S24_BE) |
36 - (1ul << SND_PCM_FORMAT_S32_LE) |
37 - (1ul << SND_PCM_FORMAT_S32_BE) |
38 - (1ul << SND_PCM_FORMAT_FLOAT_LE) |
39 - (1ul << SND_PCM_FORMAT_FLOAT_BE) |
40 - (1ul << SND_PCM_FORMAT_FLOAT64_LE) |
41 - (1ul << SND_PCM_FORMAT_FLOAT64_BE) |
42 - (1ul << SND_PCM_FORMAT_MU_LAW) |
43 - (1ul << SND_PCM_FORMAT_A_LAW) |
44 - (1ul << SND_PCM_FORMAT_S24_3LE) |
45 - (1ul << SND_PCM_FORMAT_S24_3BE) |
46 - (1ul << SND_PCM_FORMAT_S20_3LE) |
47 - (1ul << SND_PCM_FORMAT_S20_3BE) |
48 - (1ul << SND_PCM_FORMAT_S18_3LE) |
49 - (1ul << SND_PCM_FORMAT_S18_3BE),
50 + (1ull << SND_PCM_FORMAT_U8) |
51 + (1ull << SND_PCM_FORMAT_S16_LE) |
52 + (1ull << SND_PCM_FORMAT_S16_BE) |
53 + (1ull << SND_PCM_FORMAT_S24_LE) |
54 + (1ull << SND_PCM_FORMAT_S24_BE) |
55 + (1ull << SND_PCM_FORMAT_S32_LE) |
56 + (1ull << SND_PCM_FORMAT_S32_BE) |
57 + (1ull << SND_PCM_FORMAT_FLOAT_LE) |
58 + (1ull << SND_PCM_FORMAT_FLOAT_BE) |
59 + (1ull << SND_PCM_FORMAT_FLOAT64_LE) |
60 + (1ull << SND_PCM_FORMAT_FLOAT64_BE) |
61 + (1ull << SND_PCM_FORMAT_MU_LAW) |
62 + (1ull << SND_PCM_FORMAT_A_LAW) |
63 + (1ull << SND_PCM_FORMAT_S24_3LE) |
64 + (1ull << SND_PCM_FORMAT_S24_3BE) |
65 + (1ull << SND_PCM_FORMAT_S20_3LE) |
66 + (1ull << SND_PCM_FORMAT_S20_3BE) |
67 + (1ull << SND_PCM_FORMAT_S18_3LE) |
68 + (1ull << SND_PCM_FORMAT_S18_3BE),
69 [CONTAINER_FORMAT_AU] =
70 - (1ul << SND_PCM_FORMAT_S8) |
71 - (1ul << SND_PCM_FORMAT_S16_BE) |
72 - (1ul << SND_PCM_FORMAT_S32_BE) |
73 - (1ul << SND_PCM_FORMAT_FLOAT_BE) |
74 - (1ul << SND_PCM_FORMAT_FLOAT64_BE) |
75 - (1ul << SND_PCM_FORMAT_MU_LAW) |
76 - (1ul << SND_PCM_FORMAT_A_LAW),
77 + (1ull << SND_PCM_FORMAT_S8) |
78 + (1ull << SND_PCM_FORMAT_S16_BE) |
79 + (1ull << SND_PCM_FORMAT_S32_BE) |
80 + (1ull << SND_PCM_FORMAT_FLOAT_BE) |
81 + (1ull << SND_PCM_FORMAT_FLOAT64_BE) |
82 + (1ull << SND_PCM_FORMAT_MU_LAW) |
83 + (1ull << SND_PCM_FORMAT_A_LAW),
84 [CONTAINER_FORMAT_VOC] =
85 - (1ul << SND_PCM_FORMAT_U8) |
86 - (1ul << SND_PCM_FORMAT_S16_LE) |
87 - (1ul << SND_PCM_FORMAT_MU_LAW) |
88 - (1ul << SND_PCM_FORMAT_A_LAW),
89 + (1ull << SND_PCM_FORMAT_U8) |
90 + (1ull << SND_PCM_FORMAT_S16_LE) |
91 + (1ull << SND_PCM_FORMAT_MU_LAW) |
92 + (1ull << SND_PCM_FORMAT_A_LAW),
93 [CONTAINER_FORMAT_RAW] =
94 - (1ul << SND_PCM_FORMAT_S8) |
95 - (1ul << SND_PCM_FORMAT_U8) |
96 - (1ul << SND_PCM_FORMAT_S16_LE) |
97 - (1ul << SND_PCM_FORMAT_S16_BE) |
98 - (1ul << SND_PCM_FORMAT_U16_LE) |
99 - (1ul << SND_PCM_FORMAT_U16_BE) |
100 - (1ul << SND_PCM_FORMAT_S24_LE) |
101 - (1ul << SND_PCM_FORMAT_S24_BE) |
102 - (1ul << SND_PCM_FORMAT_U24_LE) |
103 - (1ul << SND_PCM_FORMAT_U24_BE) |
104 - (1ul << SND_PCM_FORMAT_S32_LE) |
105 - (1ul << SND_PCM_FORMAT_S32_BE) |
106 - (1ul << SND_PCM_FORMAT_U32_LE) |
107 - (1ul << SND_PCM_FORMAT_U32_BE) |
108 - (1ul << SND_PCM_FORMAT_FLOAT_LE) |
109 - (1ul << SND_PCM_FORMAT_FLOAT_BE) |
110 - (1ul << SND_PCM_FORMAT_FLOAT64_LE) |
111 - (1ul << SND_PCM_FORMAT_FLOAT64_BE) |
112 - (1ul << SND_PCM_FORMAT_IEC958_SUBFRAME_LE) |
113 - (1ul << SND_PCM_FORMAT_IEC958_SUBFRAME_BE) |
114 - (1ul << SND_PCM_FORMAT_MU_LAW) |
115 - (1ul << SND_PCM_FORMAT_A_LAW) |
116 - (1ul << SND_PCM_FORMAT_S24_3LE) |
117 - (1ul << SND_PCM_FORMAT_S24_3BE) |
118 - (1ul << SND_PCM_FORMAT_U24_3LE) |
119 - (1ul << SND_PCM_FORMAT_U24_3BE) |
120 - (1ul << SND_PCM_FORMAT_S20_3LE) |
121 - (1ul << SND_PCM_FORMAT_S20_3BE) |
122 - (1ul << SND_PCM_FORMAT_U20_3LE) |
123 - (1ul << SND_PCM_FORMAT_U20_3BE) |
124 - (1ul << SND_PCM_FORMAT_S18_3LE) |
125 - (1ul << SND_PCM_FORMAT_S18_3BE) |
126 - (1ul << SND_PCM_FORMAT_U18_3LE) |
127 - (1ul << SND_PCM_FORMAT_U18_3BE) |
128 - (1ul << SND_PCM_FORMAT_DSD_U8) |
129 - (1ul << SND_PCM_FORMAT_DSD_U16_LE) |
130 - (1ul << SND_PCM_FORMAT_DSD_U32_LE) |
131 - (1ul << SND_PCM_FORMAT_DSD_U16_BE) |
132 - (1ul << SND_PCM_FORMAT_DSD_U32_BE),
133 + (1ull << SND_PCM_FORMAT_S8) |
134 + (1ull << SND_PCM_FORMAT_U8) |
135 + (1ull << SND_PCM_FORMAT_S16_LE) |
136 + (1ull << SND_PCM_FORMAT_S16_BE) |
137 + (1ull << SND_PCM_FORMAT_U16_LE) |
138 + (1ull << SND_PCM_FORMAT_U16_BE) |
139 + (1ull << SND_PCM_FORMAT_S24_LE) |
140 + (1ull << SND_PCM_FORMAT_S24_BE) |
141 + (1ull << SND_PCM_FORMAT_U24_LE) |
142 + (1ull << SND_PCM_FORMAT_U24_BE) |
143 + (1ull << SND_PCM_FORMAT_S32_LE) |
144 + (1ull << SND_PCM_FORMAT_S32_BE) |
145 + (1ull << SND_PCM_FORMAT_U32_LE) |
146 + (1ull << SND_PCM_FORMAT_U32_BE) |
147 + (1ull << SND_PCM_FORMAT_FLOAT_LE) |
148 + (1ull << SND_PCM_FORMAT_FLOAT_BE) |
149 + (1ull << SND_PCM_FORMAT_FLOAT64_LE) |
150 + (1ull << SND_PCM_FORMAT_FLOAT64_BE) |
151 + (1ull << SND_PCM_FORMAT_IEC958_SUBFRAME_LE) |
152 + (1ull << SND_PCM_FORMAT_IEC958_SUBFRAME_BE) |
153 + (1ull << SND_PCM_FORMAT_MU_LAW) |
154 + (1ull << SND_PCM_FORMAT_A_LAW) |
155 + (1ull << SND_PCM_FORMAT_S24_3LE) |
156 + (1ull << SND_PCM_FORMAT_S24_3BE) |
157 + (1ull << SND_PCM_FORMAT_U24_3LE) |
158 + (1ull << SND_PCM_FORMAT_U24_3BE) |
159 + (1ull << SND_PCM_FORMAT_S20_3LE) |
160 + (1ull << SND_PCM_FORMAT_S20_3BE) |
161 + (1ull << SND_PCM_FORMAT_U20_3LE) |
162 + (1ull << SND_PCM_FORMAT_U20_3BE) |
163 + (1ull << SND_PCM_FORMAT_S18_3LE) |
164 + (1ull << SND_PCM_FORMAT_S18_3BE) |
165 + (1ull << SND_PCM_FORMAT_U18_3LE) |
166 + (1ull << SND_PCM_FORMAT_U18_3BE) |
167 + (1ull << SND_PCM_FORMAT_DSD_U8) |
168 + (1ull << SND_PCM_FORMAT_DSD_U16_LE) |
169 + (1ull << SND_PCM_FORMAT_DSD_U32_LE) |
170 + (1ull << SND_PCM_FORMAT_DSD_U16_BE) |
171 + (1ull << SND_PCM_FORMAT_DSD_U32_BE),
173 static const uint64_t access_mask =
174 - (1ul << SND_PCM_ACCESS_MMAP_INTERLEAVED) |
175 - (1ul << SND_PCM_ACCESS_RW_INTERLEAVED);
176 + (1ull << SND_PCM_ACCESS_MMAP_INTERLEAVED) |
177 + (1ull << SND_PCM_ACCESS_RW_INTERLEAVED);
178 struct test_generator gen = {0};
179 struct container_trial *trial;
181 diff --git a/axfer/test/generator.c b/axfer/test/generator.c
182 index cdea2c9..bde8c5f 100644
183 --- a/axfer/test/generator.c
184 +++ b/axfer/test/generator.c
185 @@ -220,7 +220,7 @@ static int test_sample_format(struct test_generator *gen,
188 for (i = 0; i <= SND_PCM_FORMAT_LAST; ++i) {
189 - if (!((1ul << i) & gen->sample_format_mask))
190 + if (!((1ull << i) & gen->sample_format_mask))
193 err = test_samples_per_frame(gen, access, i);
194 @@ -237,7 +237,7 @@ static int test_access(struct test_generator *gen)
197 for (i = 0; i <= SND_PCM_ACCESS_LAST; ++i) {
198 - if (!((1ul << i) & gen->access_mask))
199 + if (!((1ull << i) & gen->access_mask))
202 err = test_sample_format(gen, i);
203 diff --git a/axfer/test/mapper-test.c b/axfer/test/mapper-test.c
204 index 6b24d54..f0376c7 100644
205 --- a/axfer/test/mapper-test.c
206 +++ b/axfer/test/mapper-test.c
207 @@ -396,13 +396,13 @@ int main(int argc, const char *argv[])
209 // Test 8/16/18/20/24/32/64 bytes per sample.
210 static const uint64_t sample_format_mask =
211 - (1ul << SND_PCM_FORMAT_U8) |
212 - (1ul << SND_PCM_FORMAT_S16_LE) |
213 - (1ul << SND_PCM_FORMAT_S18_3LE) |
214 - (1ul << SND_PCM_FORMAT_S20_3LE) |
215 - (1ul << SND_PCM_FORMAT_S24_LE) |
216 - (1ul << SND_PCM_FORMAT_S32_LE) |
217 - (1ul << SND_PCM_FORMAT_FLOAT64_LE);
218 + (1ull << SND_PCM_FORMAT_U8) |
219 + (1ull << SND_PCM_FORMAT_S16_LE) |
220 + (1ull << SND_PCM_FORMAT_S18_3LE) |
221 + (1ull << SND_PCM_FORMAT_S20_3LE) |
222 + (1ull << SND_PCM_FORMAT_S24_LE) |
223 + (1ull << SND_PCM_FORMAT_S32_LE) |
224 + (1ull << SND_PCM_FORMAT_FLOAT64_LE);
225 uint64_t access_mask;
226 struct test_generator gen = {0};
227 struct mapper_trial *trial;
228 @@ -451,13 +451,13 @@ int main(int argc, const char *argv[])
232 - access_mask = 1ul << access;
233 + access_mask = 1ull << access;
236 - access_mask = (1ul << SND_PCM_ACCESS_MMAP_INTERLEAVED) |
237 - (1ul << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) |
238 - (1ul << SND_PCM_ACCESS_RW_INTERLEAVED) |
239 - (1ul << SND_PCM_ACCESS_RW_NONINTERLEAVED);
240 + access_mask = (1ull << SND_PCM_ACCESS_MMAP_INTERLEAVED) |
241 + (1ull << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) |
242 + (1ull << SND_PCM_ACCESS_RW_INTERLEAVED) |
243 + (1ull << SND_PCM_ACCESS_RW_NONINTERLEAVED);