Skip to content

Commit

Permalink
Add fallthrough attribute to suppress GCC 7 warnings
Browse files Browse the repository at this point in the history
GCC 7 warns when fallthrough occurs in a switch statement, unless a
fallthrough attribute is defined. Add this fallthrough element, hidden
behind a macro.
  • Loading branch information
aklomp committed Aug 9, 2017
1 parent c9804af commit b6417f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/arch/generic/dec_tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
st.carry = q << 2;
st.bytes++;

// Deliberate fallthrough:
BASE64_FALLTHROUGH

case 1: if (srclen-- == 0) {
ret = 1;
break;
Expand All @@ -24,6 +27,9 @@
st.bytes++;
outl++;

// Deliberate fallthrough:
BASE64_FALLTHROUGH

case 2: if (srclen-- == 0) {
ret = 1;
break;
Expand Down Expand Up @@ -56,6 +62,9 @@
st.bytes++;
outl++;

// Deliberate fallthrough:
BASE64_FALLTHROUGH

case 3: if (srclen-- == 0) {
ret = 1;
break;
Expand Down
6 changes: 6 additions & 0 deletions lib/arch/generic/enc_tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
st.bytes++;
outl += 1;

// Deliberate fallthrough:
BASE64_FALLTHROUGH

case 1: if (srclen-- == 0) {
break;
}
Expand All @@ -14,6 +17,9 @@
st.bytes++;
outl += 1;

// Deliberate fallthrough:
BASE64_FALLTHROUGH

case 2: if (srclen-- == 0) {
break;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ struct codec
// End-of-file when stream end has been reached or invalid input provided:
#define BASE64_EOF 2

// GCC 7 defaults to issuing a warning for fallthrough in switch statements,
// unless the fallthrough cases are marked with an attribute. As we use
// fallthrough deliberately, define an alias for the attribute:
#if __GNUC__ >= 7
#define BASE64_FALLTHROUGH __attribute__((fallthrough));
#else
#define BASE64_FALLTHROUGH
#endif

void codec_choose (struct codec *, int flags);
extern void codec_choose (struct codec *, int flags);

// These tables are used by all codecs
// for fallback plain encoding/decoding:
Expand Down

0 comments on commit b6417f3

Please sign in to comment.