Skip to content

Commit bbbe4ee

Browse files
committed
Add extra warnings
The main things these picked up are fall-throughs on switch statements, all of which were deliberate. However they're now annotated as such so no longer complain. In samtools this did detect a genuine bug so it's worth adding (and annotating to silence FPs)
1 parent 1654891 commit bbbe4ee

5 files changed

Lines changed: 28 additions & 19 deletions

File tree

.cirrus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ task:
4040
compile_script:
4141
- autoreconf -i
4242
- ./configure CC="clang" --disable-shared
43-
- make -j4 CFLAGS="-g -O3 -Wall -Werror"
43+
- make -j4 CFLAGS="-g -O3 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter"
4444

4545
test_script:
46-
- make check CFLAGS="-g -O3 -Wall -Werror"
46+
- make check CFLAGS="-g -O3 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter"
4747
- make distcheck
4848

4949
# Rocky Linux

htscodecs/pack.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ uint8_t *hts_pack(uint8_t *data, int64_t len,
109109
out[j] = 0;
110110
int s = len-i, x = 0;
111111
switch (s) {
112-
case 3: out[j] |= p[data[i++]] << x; x+=2;
113-
case 2: out[j] |= p[data[i++]] << x; x+=2;
112+
case 3: out[j] |= p[data[i++]] << x; x+=2; // fall-through
113+
case 2: out[j] |= p[data[i++]] << x; x+=2; // fall-through
114114
case 1: out[j] |= p[data[i++]] << x; x+=2;
115115
j++;
116116
}
@@ -125,12 +125,12 @@ uint8_t *hts_pack(uint8_t *data, int64_t len,
125125
out[j] = 0;
126126
int s = len-i, x = 0;
127127
switch (s) {
128-
case 7: out[j] |= p[data[i++]] << x++;
129-
case 6: out[j] |= p[data[i++]] << x++;
130-
case 5: out[j] |= p[data[i++]] << x++;
131-
case 4: out[j] |= p[data[i++]] << x++;
132-
case 3: out[j] |= p[data[i++]] << x++;
133-
case 2: out[j] |= p[data[i++]] << x++;
128+
case 7: out[j] |= p[data[i++]] << x++; // fall-through
129+
case 6: out[j] |= p[data[i++]] << x++; // fall-through
130+
case 5: out[j] |= p[data[i++]] << x++; // fall-through
131+
case 4: out[j] |= p[data[i++]] << x++; // fall-through
132+
case 3: out[j] |= p[data[i++]] << x++; // fall-through
133+
case 2: out[j] |= p[data[i++]] << x++; // fall-through
134134
case 1: out[j] |= p[data[i++]] << x++;
135135
j++;
136136
}

htscodecs/rANS_static.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ unsigned char *rans_compress_O0(unsigned char *in, unsigned int in_size,
167167

168168
switch (i=(in_size&3)) {
169169
case 3: RansEncPutSymbol(&rans2, &ptr, &syms[in[in_size-(i-2)]]);
170+
// fall-through
170171
case 2: RansEncPutSymbol(&rans1, &ptr, &syms[in[in_size-(i-1)]]);
172+
// fall-through
171173
case 1: RansEncPutSymbol(&rans0, &ptr, &syms[in[in_size-(i-0)]]);
174+
// fall-through
172175
case 0:
173176
break;
174177
}
@@ -361,10 +364,13 @@ unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size,
361364
switch(out_sz&3) {
362365
case 3:
363366
out_buf[out_end + 2] = ssym[R[2] & mask];
367+
// fall-through
364368
case 2:
365369
out_buf[out_end + 1] = ssym[R[1] & mask];
370+
// fall-through
366371
case 1:
367372
out_buf[out_end] = ssym[R[0] & mask];
373+
// fall-through
368374
default:
369375
break;
370376
}

htscodecs/rANS_static4x16pr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ unsigned char *rans_compress_O0_4x16(unsigned char *in, unsigned int in_size,
176176

177177
switch (i=(in_size&3)) {
178178
case 3: RansEncPutSymbol(&rans2, &ptr, &syms[in[in_size-(i-2)]]);
179+
// fall-through
179180
case 2: RansEncPutSymbol(&rans1, &ptr, &syms[in[in_size-(i-1)]]);
181+
// fall-through
180182
case 1: RansEncPutSymbol(&rans0, &ptr, &syms[in[in_size-(i-0)]]);
183+
// fall-through
181184
case 0:
182185
break;
183186
}

htscodecs/tokenise_name3.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ static void free_context(name_context *ctx) {
232232
// Returns number of bytes written.
233233
static int append_uint32_fixed(char *cp, uint32_t i, uint8_t l) {
234234
switch (l) {
235-
case 9:*cp++ = i / 100000000 + '0', i %= 100000000;
236-
case 8:*cp++ = i / 10000000 + '0', i %= 10000000;
237-
case 7:*cp++ = i / 1000000 + '0', i %= 1000000;
238-
case 6:*cp++ = i / 100000 + '0', i %= 100000;
239-
case 5:*cp++ = i / 10000 + '0', i %= 10000;
240-
case 4:*cp++ = i / 1000 + '0', i %= 1000;
241-
case 3:*cp++ = i / 100 + '0', i %= 100;
242-
case 2:*cp++ = i / 10 + '0', i %= 10;
243-
case 1:*cp++ = i + '0';
235+
case 9:*cp++ = i / 100000000 + '0', i %= 100000000; // fall-through
236+
case 8:*cp++ = i / 10000000 + '0', i %= 10000000; // fall-through
237+
case 7:*cp++ = i / 1000000 + '0', i %= 1000000; // fall-through
238+
case 6:*cp++ = i / 100000 + '0', i %= 100000; // fall-through
239+
case 5:*cp++ = i / 10000 + '0', i %= 10000; // fall-through
240+
case 4:*cp++ = i / 1000 + '0', i %= 1000; // fall-through
241+
case 3:*cp++ = i / 100 + '0', i %= 100; // fall-through
242+
case 2:*cp++ = i / 10 + '0', i %= 10; // fall-through
243+
case 1:*cp++ = i + '0'; // fall-throuhg
244244
case 0:break;
245245
}
246246
return l;

0 commit comments

Comments
 (0)