Skip to content

Commit c8b30df

Browse files
nicowilliamsemanuele6
authored andcommitted
Add JQ_FALLTHROUGH and use it to quiet warnings
1 parent a6eb055 commit c8b30df

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/execute.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ jv jq_next(jq_state *jq) {
575575

576576
case STOREVN:
577577
stack_save(jq, pc - 1, stack_get_pos(jq));
578+
JQ_FALLTHROUGH;
578579
case STOREV: {
579580
uint16_t level = *pc++;
580581
uint16_t v = *pc++;
@@ -742,7 +743,7 @@ jv jq_next(jq_state *jq) {
742743
}
743744
stack_push(jq, container);
744745
stack_push(jq, jv_number(-1));
745-
// fallthrough
746+
JQ_FALLTHROUGH;
746747
}
747748
case ON_BACKTRACK(EACH):
748749
case ON_BACKTRACK(EACH_OPT): {

src/jv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,9 @@ static uint32_t jvp_string_hash(jv jstr) {
12221222

12231223
switch(len & 3) {
12241224
case 3: k1 ^= tail[2] << 16;
1225+
JQ_FALLTHROUGH;
12251226
case 2: k1 ^= tail[1] << 8;
1227+
JQ_FALLTHROUGH;
12261228
case 1: k1 ^= tail[0];
12271229
k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1;
12281230
}

src/jv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
#include <stdint.h>
66
#include <stdio.h>
77

8+
#if (defined(__GNUC__) && __GNUC__ >= 7) || \
9+
(defined(__clang__) && __clang_major__ >= 10)
10+
# define JQ_FALLTHROUGH __attribute__((fallthrough))
11+
#else
12+
# define JQ_FALLTHROUGH do {} while (0) /* fallthrough */
13+
#endif
14+
815
typedef enum {
916
JV_KIND_INVALID,
1017
JV_KIND_NULL,

src/jv_dtoa.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
#include "jv_dtoa.h"
196196

197197
#include "jv_alloc.h"
198+
#include "jv.h"
198199
#define MALLOC jv_mem_alloc
199200
#define FREE jv_mem_free
200201

@@ -1723,6 +1724,7 @@ gethex(struct dtoa_context* C, CONST char **sp, U *rvp, int rounding, int sign)
17231724
case '-':
17241725
esign = 1;
17251726
/* no break */
1727+
JQ_FALLTHROUGH;
17261728
case '+':
17271729
s++;
17281730
}
@@ -2327,7 +2329,10 @@ bigcomp
23272329
jvp_strtod
23282330
(struct dtoa_context* C, const char *s00, char **se)
23292331
{
2330-
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1, test_scale;
2332+
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
2333+
#ifdef Honor_FLT_ROUNDS
2334+
int test_scale;
2335+
#endif
23312336
int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
23322337
CONST char *s, *s0, *s1;
23332338
double aadj, aadj1;
@@ -2367,10 +2372,12 @@ jvp_strtod
23672372
case '-':
23682373
sign = 1;
23692374
/* no break */
2375+
JQ_FALLTHROUGH;
23702376
case '+':
23712377
if (*++s)
23722378
goto break2;
23732379
/* no break */
2380+
JQ_FALLTHROUGH;
23742381
case 0:
23752382
goto ret0;
23762383
case '\t':
@@ -2478,6 +2485,7 @@ jvp_strtod
24782485
switch(c = *++s) {
24792486
case '-':
24802487
esign = 1;
2488+
JQ_FALLTHROUGH;
24812489
case '+':
24822490
c = *++s;
24832491
}
@@ -3699,6 +3707,7 @@ jvp_dtoa
36993707
case 2:
37003708
leftright = 0;
37013709
/* no break */
3710+
JQ_FALLTHROUGH;
37023711
case 4:
37033712
if (ndigits <= 0)
37043713
ndigits = 1;
@@ -3707,6 +3716,7 @@ jvp_dtoa
37073716
case 3:
37083717
leftright = 0;
37093718
/* no break */
3719+
JQ_FALLTHROUGH;
37103720
case 5:
37113721
i = ndigits + k + 1;
37123722
ilim = i;

0 commit comments

Comments
 (0)