Skip to content

Commit

Permalink
Add JQ_FALLTHROUGH and use it to quiet warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams authored and emanuele6 committed Jul 30, 2023
1 parent a6eb055 commit c8b30df
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ jv jq_next(jq_state *jq) {

case STOREVN:
stack_save(jq, pc - 1, stack_get_pos(jq));
JQ_FALLTHROUGH;
case STOREV: {
uint16_t level = *pc++;
uint16_t v = *pc++;
Expand Down Expand Up @@ -742,7 +743,7 @@ jv jq_next(jq_state *jq) {
}
stack_push(jq, container);
stack_push(jq, jv_number(-1));
// fallthrough
JQ_FALLTHROUGH;
}
case ON_BACKTRACK(EACH):
case ON_BACKTRACK(EACH_OPT): {
Expand Down
2 changes: 2 additions & 0 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,9 @@ static uint32_t jvp_string_hash(jv jstr) {

switch(len & 3) {
case 3: k1 ^= tail[2] << 16;
JQ_FALLTHROUGH;
case 2: k1 ^= tail[1] << 8;
JQ_FALLTHROUGH;
case 1: k1 ^= tail[0];
k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1;
}
Expand Down
7 changes: 7 additions & 0 deletions src/jv.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include <stdint.h>
#include <stdio.h>

#if (defined(__GNUC__) && __GNUC__ >= 7) || \
(defined(__clang__) && __clang_major__ >= 10)
# define JQ_FALLTHROUGH __attribute__((fallthrough))
#else
# define JQ_FALLTHROUGH do {} while (0) /* fallthrough */
#endif

typedef enum {
JV_KIND_INVALID,
JV_KIND_NULL,
Expand Down
12 changes: 11 additions & 1 deletion src/jv_dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
#include "jv_dtoa.h"

#include "jv_alloc.h"
#include "jv.h"
#define MALLOC jv_mem_alloc
#define FREE jv_mem_free

Expand Down Expand Up @@ -1723,6 +1724,7 @@ gethex(struct dtoa_context* C, CONST char **sp, U *rvp, int rounding, int sign)
case '-':
esign = 1;
/* no break */
JQ_FALLTHROUGH;
case '+':
s++;
}
Expand Down Expand Up @@ -2327,7 +2329,10 @@ bigcomp
jvp_strtod
(struct dtoa_context* C, const char *s00, char **se)
{
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1, test_scale;
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
#ifdef Honor_FLT_ROUNDS
int test_scale;
#endif
int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
CONST char *s, *s0, *s1;
double aadj, aadj1;
Expand Down Expand Up @@ -2367,10 +2372,12 @@ jvp_strtod
case '-':
sign = 1;
/* no break */
JQ_FALLTHROUGH;
case '+':
if (*++s)
goto break2;
/* no break */
JQ_FALLTHROUGH;
case 0:
goto ret0;
case '\t':
Expand Down Expand Up @@ -2478,6 +2485,7 @@ jvp_strtod
switch(c = *++s) {
case '-':
esign = 1;
JQ_FALLTHROUGH;
case '+':
c = *++s;
}
Expand Down Expand Up @@ -3699,6 +3707,7 @@ jvp_dtoa
case 2:
leftright = 0;
/* no break */
JQ_FALLTHROUGH;
case 4:
if (ndigits <= 0)
ndigits = 1;
Expand All @@ -3707,6 +3716,7 @@ jvp_dtoa
case 3:
leftright = 0;
/* no break */
JQ_FALLTHROUGH;
case 5:
i = ndigits + k + 1;
ilim = i;
Expand Down

0 comments on commit c8b30df

Please sign in to comment.