Skip to content

Commit

Permalink
lib: Fix fall-through warnings for Clang
Browse files Browse the repository at this point in the history
In preparation to enable -Wimplicit-fallthrough for Clang, fix multiple
warnings by explicitly adding multiple break statements instead of
letting the code fall through to the next case, and by replacing a
number of /* fall through */ comments with the new pseudo-keyword
macro fallthrough.

Notice that Clang doesn't recognize /* Fall through */ comments as
implicit fall-through markings.

Link: KSPP#115
Signed-off-by: Gustavo A. R. Silva <[email protected]>
  • Loading branch information
GustavoARSilva committed Nov 19, 2020
1 parent 49a4136 commit 36f9ff9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ unsigned long long memparse(const char *ptr, char **retptr)
case 'k':
ret <<= 10;
endptr++;
fallthrough;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions lib/kstrtox.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ int kstrtobool(const char *s, bool *res)
default:
break;
}
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/nlattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static int validate_nla(const struct nlattr *nla, int maxtype,
err = -EINVAL;
goto out_err;
}
/* fall through */
fallthrough;

case NLA_STRING:
if (attrlen < 1)
Expand Down
1 change: 1 addition & 0 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,7 @@ int format_decode(const char *fmt, struct printf_spec *spec)
case 'd':
case 'i':
spec->flags |= SIGN;
break;
case 'u':
break;

Expand Down
24 changes: 12 additions & 12 deletions lib/zlib_inflate/inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,18 @@ int zlib_inflate(z_streamp strm, int flush)
strm->adler = state->check = REVERSE(hold);
INITBITS();
state->mode = DICT;
/* fall through */
fallthrough;
case DICT:
if (state->havedict == 0) {
RESTORE();
return Z_NEED_DICT;
}
strm->adler = state->check = zlib_adler32(0L, NULL, 0);
state->mode = TYPE;
/* fall through */
fallthrough;
case TYPE:
if (flush == Z_BLOCK) goto inf_leave;
/* fall through */
fallthrough;
case TYPEDO:
INFLATE_TYPEDO_HOOK(strm, flush);
if (state->last) {
Expand Down Expand Up @@ -446,7 +446,7 @@ int zlib_inflate(z_streamp strm, int flush)
state->length = (unsigned)hold & 0xffff;
INITBITS();
state->mode = COPY;
/* fall through */
fallthrough;
case COPY:
copy = state->length;
if (copy) {
Expand Down Expand Up @@ -480,7 +480,7 @@ int zlib_inflate(z_streamp strm, int flush)
#endif
state->have = 0;
state->mode = LENLENS;
/* fall through */
fallthrough;
case LENLENS:
while (state->have < state->ncode) {
NEEDBITS(3);
Expand All @@ -501,7 +501,7 @@ int zlib_inflate(z_streamp strm, int flush)
}
state->have = 0;
state->mode = CODELENS;
/* fall through */
fallthrough;
case CODELENS:
while (state->have < state->nlen + state->ndist) {
for (;;) {
Expand Down Expand Up @@ -575,7 +575,7 @@ int zlib_inflate(z_streamp strm, int flush)
break;
}
state->mode = LEN;
/* fall through */
fallthrough;
case LEN:
if (have >= 6 && left >= 258) {
RESTORE();
Expand Down Expand Up @@ -615,15 +615,15 @@ int zlib_inflate(z_streamp strm, int flush)
}
state->extra = (unsigned)(this.op) & 15;
state->mode = LENEXT;
/* fall through */
fallthrough;
case LENEXT:
if (state->extra) {
NEEDBITS(state->extra);
state->length += BITS(state->extra);
DROPBITS(state->extra);
}
state->mode = DIST;
/* fall through */
fallthrough;
case DIST:
for (;;) {
this = state->distcode[BITS(state->distbits)];
Expand All @@ -649,7 +649,7 @@ int zlib_inflate(z_streamp strm, int flush)
state->offset = (unsigned)this.val;
state->extra = (unsigned)(this.op) & 15;
state->mode = DISTEXT;
/* fall through */
fallthrough;
case DISTEXT:
if (state->extra) {
NEEDBITS(state->extra);
Expand All @@ -669,7 +669,7 @@ int zlib_inflate(z_streamp strm, int flush)
break;
}
state->mode = MATCH;
/* fall through */
fallthrough;
case MATCH:
if (left == 0) goto inf_leave;
copy = out - left;
Expand Down Expand Up @@ -720,7 +720,7 @@ int zlib_inflate(z_streamp strm, int flush)
INITBITS();
}
state->mode = DONE;
/* fall through */
fallthrough;
case DONE:
ret = Z_STREAM_END;
goto inf_leave;
Expand Down
1 change: 1 addition & 0 deletions lib/zstd/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s
case 3: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[2]) << 16;
fallthrough;
case 2: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[1]) << 8;
fallthrough;
default:;
}
{
Expand Down
1 change: 1 addition & 0 deletions lib/zstd/huf_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ size_t HUF_compress1X_usingCTable(void *dst, size_t dstSize, const void *src, si
case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC);
fallthrough;
case 1: HUF_encodeSymbol(&bitC, ip[n + 0], CTable); HUF_FLUSHBITS(&bitC);
fallthrough;
case 0:
default:;
}
Expand Down

0 comments on commit 36f9ff9

Please sign in to comment.