misc: fix ggc-7 fallthrough warnings

(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-05-16 09:18:24 +01:00 committed by Karel Zak
parent 11e904f02c
commit b1557fe981
16 changed files with 26 additions and 22 deletions

View File

@ -123,7 +123,7 @@ struct entry {
#define CRAMFS_OFFSET_WIDTH 26 #define CRAMFS_OFFSET_WIDTH 26
/* Input status of 0 to print help and exit without an error. */ /* Input status of 0 to print help and exit without an error. */
static void static void __attribute__((__noreturn__))
usage(int status) { usage(int status) {
FILE *stream = status ? stderr : stdout; FILE *stream = status ? stderr : stdout;

View File

@ -830,7 +830,7 @@ static void process_wtmp_file(const struct last_control *ctl,
c = whydown; c = whydown;
quit = list(ctl, &ut, lastboot, c); quit = list(ctl, &ut, lastboot, c);
} }
/* FALLTHRU */ /* fallthrough */
case DEAD_PROCESS: case DEAD_PROCESS:
/* /*

View File

@ -899,6 +899,7 @@ su_main (int argc, char **argv, int mode)
/* fallthrough if -u <user> is not specified, then follow /* fallthrough if -u <user> is not specified, then follow
* traditional su(1) behavior * traditional su(1) behavior
*/ */
/* fallthrough */
case SU_MODE: case SU_MODE:
if (optind < argc) if (optind < argc)
new_user = argv[optind++]; new_user = argv[optind++];

View File

@ -267,11 +267,11 @@ static void tcfinal(struct console *con)
break; break;
case 1: /* odd parity */ case 1: /* odd parity */
tio->c_cflag |= PARODD; tio->c_cflag |= PARODD;
/* fall through */ /* fallthrough */
case 2: /* even parity */ case 2: /* even parity */
tio->c_cflag |= PARENB; tio->c_cflag |= PARENB;
tio->c_iflag |= (INPCK | ISTRIP); tio->c_iflag |= (INPCK | ISTRIP);
/* fall through */ /* fallthrough */
case (1 | 2): /* no parity bit */ case (1 | 2): /* no parity bit */
tio->c_cflag &= ~CSIZE; tio->c_cflag &= ~CSIZE;
tio->c_cflag |= CS7; tio->c_cflag |= CS7;
@ -971,7 +971,6 @@ int main(int argc, char **argv)
switch ((con->pid = fork())) { switch ((con->pid = fork())) {
case 0: case 0:
mask_signal(SIGCHLD, SIG_DFL, NULL); mask_signal(SIGCHLD, SIG_DFL, NULL);
/* fall through */
nofork: nofork:
setup(con); setup(con);
while (1) { while (1) {
@ -1024,7 +1023,7 @@ int main(int argc, char **argv)
exit(0); exit(0);
case -1: case -1:
warn(_("fork failed")); warn(_("fork failed"));
/* fall through */ /* fallthrough */
default: default:
break; break;
} }

View File

@ -431,7 +431,7 @@ int main(int argc, char **argv)
ctl.req.day = strtos32_or_err(*argv++, _("illegal day value")); ctl.req.day = strtos32_or_err(*argv++, _("illegal day value"));
if (ctl.req.day < 1 || DAYS_IN_MONTH < ctl.req.day) if (ctl.req.day < 1 || DAYS_IN_MONTH < ctl.req.day)
errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), DAYS_IN_MONTH); errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), DAYS_IN_MONTH);
/* FALLTHROUGH */ /* fallthrough */
case 2: case 2:
if (isdigit(**argv)) if (isdigit(**argv))
ctl.req.month = strtos32_or_err(*argv++, _("illegal month value: use 1-12")); ctl.req.month = strtos32_or_err(*argv++, _("illegal month value: use 1-12"));
@ -443,7 +443,7 @@ int main(int argc, char **argv)
} }
if (ctl.req.month < 1 || MONTHS_IN_YEAR < ctl.req.month) if (ctl.req.month < 1 || MONTHS_IN_YEAR < ctl.req.month)
errx(EXIT_FAILURE, _("illegal month value: use 1-12")); errx(EXIT_FAILURE, _("illegal month value: use 1-12"));
/* FALLTHROUGH */ /* fallthrough */
case 1: case 1:
ctl.req.year = strtos32_or_err(*argv++, _("illegal year value")); ctl.req.year = strtos32_or_err(*argv++, _("illegal year value"));
if (ctl.req.year < SMALLEST_YEAR) if (ctl.req.year < SMALLEST_YEAR)

View File

@ -189,7 +189,6 @@ int main(int argc, char **argv)
return EXIT_SUCCESS; return EXIT_SUCCESS;
case 'h': case 'h':
usage(stdout); usage(stdout);
/* fallthrough */
default: default:
errtryhelp(EXIT_FAILURE); errtryhelp(EXIT_FAILURE);
} }

View File

@ -305,7 +305,7 @@ int main(int argc, char *argv[])
if (open_flags & O_RDWR) if (open_flags & O_RDWR)
break; break;
} }
/* go through */ /* fallthrough */
default: default:
/* Other errors */ /* Other errors */
if (filename) if (filename)

View File

@ -1209,7 +1209,8 @@ static void out_version(void)
* fmt, ... ), show a usage information and terminate the program * fmt, ... ), show a usage information and terminate the program
* afterwards. * afterwards.
*/ */
static void usage(const struct hwclock_control *ctl, const char *fmt, ...) static void __attribute__((__noreturn__))
usage(const struct hwclock_control *ctl, const char *fmt, ...)
{ {
FILE *usageto; FILE *usageto;
va_list ap; va_list ap;

View File

@ -346,6 +346,7 @@ int main(int argc, char **argv)
ret++; ret++;
break; break;
} }
/* fallthrough */
case 'm': case 'm':
if (!iskey) if (!iskey)
id = strtos32_or_err(optarg, _("failed to parse argument")); id = strtos32_or_err(optarg, _("failed to parse argument"));
@ -359,6 +360,7 @@ int main(int argc, char **argv)
ret++; ret++;
break; break;
} }
/* fallthrough */
case 'q': case 'q':
if (!iskey) if (!iskey)
id = strtos32_or_err(optarg, _("failed to parse argument")); id = strtos32_or_err(optarg, _("failed to parse argument"));
@ -372,6 +374,7 @@ int main(int argc, char **argv)
ret++; ret++;
break; break;
} }
/* fallthrough */
case 's': case 's':
if (!iskey) if (!iskey)
id = strtos32_or_err(optarg, _("failed to parse argument")); id = strtos32_or_err(optarg, _("failed to parse argument"));

View File

@ -65,7 +65,7 @@ static struct namespace_file {
{ .nstype = 0, .name = NULL, .fd = -1 } { .nstype = 0, .name = NULL, .fd = -1 }
}; };
static void usage(int status) static void __attribute__((__noreturn__)) usage(int status)
{ {
FILE *out = status == EXIT_SUCCESS ? stdout : stderr; FILE *out = status == EXIT_SUCCESS ? stdout : stderr;

View File

@ -238,7 +238,7 @@ static void bind_ns_files_from_child(pid_t *child, int fds[2])
} }
} }
static void usage(int status) static void __attribute__((__noreturn__)) usage(int status)
{ {
FILE *out = status == EXIT_SUCCESS ? stdout : stderr; FILE *out = status == EXIT_SUCCESS ? stdout : stderr;

View File

@ -2041,12 +2041,12 @@ static void termio_final(struct options *op, struct termios *tp, struct chardata
case 1: case 1:
/* odd parity */ /* odd parity */
tp->c_cflag |= PARODD; tp->c_cflag |= PARODD;
/* do not break */ /* fallthrough */
case 2: case 2:
/* even parity */ /* even parity */
tp->c_cflag |= PARENB; tp->c_cflag |= PARENB;
tp->c_iflag |= INPCK | ISTRIP; tp->c_iflag |= INPCK | ISTRIP;
/* do not break */ /* fallthrough */
case (1 | 2): case (1 | 2):
/* no parity bit */ /* no parity bit */
tp->c_cflag &= ~CSIZE; tp->c_cflag &= ~CSIZE;

View File

@ -351,7 +351,7 @@ isint: cs[3] = '\0';
case 'A': case 'A':
endfu = fu; endfu = fu;
fu->flags |= F_IGNORE; fu->flags |= F_IGNORE;
/* FALLTHROUGH */ /* fallthrough */
case 'a': case 'a':
pr->flags = F_ADDRESS; pr->flags = F_ADDRESS;
++p2; ++p2;

View File

@ -1270,7 +1270,7 @@ int command(char *filename, register FILE *f)
break; break;
} }
lastp++; lastp++;
/* fall through */ /* fallthrough */
case '/': case '/':
if (nlines == 0) if (nlines == 0)
nlines++; nlines++;
@ -1368,7 +1368,7 @@ int command(char *filename, register FILE *f)
(char *)0); (char *)0);
break; break;
} }
/* fall through */ /* fallthrough */
default: default:
if (dum_opt) { if (dum_opt) {
kill_line(); kill_line();
@ -2023,6 +2023,7 @@ int expand(char **outbuf, char *inbuf)
*outstr++ = *inpstr++; *outstr++ = *inpstr++;
break; break;
} }
/* fallthrough */
default: default:
*outstr++ = c; *outstr++ = c;
} }

View File

@ -659,7 +659,7 @@ static void prompt(long long pageno)
break; break;
case SEARCH_FIN: case SEARCH_FIN:
state = SEARCH; state = SEARCH;
/* FALLTHRU */ /* fallthrough */
case SEARCH: case SEARCH:
if (cmd.cmdline[cmd.cmdlen - 1] == '\\') { if (cmd.cmdline[cmd.cmdlen - 1] == '\\') {
escape = 1; escape = 1;
@ -738,7 +738,7 @@ static void prompt(long long pageno)
continue; continue;
} }
state = COUNT; state = COUNT;
/* FALLTHRU */ /* fallthrough */
case COUNT: case COUNT:
break; break;
case ADDON_FIN: case ADDON_FIN:

View File

@ -208,7 +208,7 @@ int main(int argc, char **argv)
default: default:
warnx(_("trouble reading terminfo")); warnx(_("trouble reading terminfo"));
/* fall through to ... */ /* fallthrough */
case 0: case 0:
if (tflag) if (tflag)
@ -317,7 +317,7 @@ static void filter(FILE *f)
} }
obuf[col].c_char = '_'; obuf[col].c_char = '_';
obuf[col].c_width = 1; obuf[col].c_width = 1;
/* fall through */ /* fallthrough */
case ' ': case ' ':
setcol(col + 1); setcol(col + 1);
continue; continue;