]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: fix ggc-7 fallthrough warnings
authorSami Kerola <kerolasa@iki.fi>
Tue, 16 May 2017 08:18:24 +0000 (09:18 +0100)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Tue, 13 Jun 2017 19:47:17 +0000 (21:47 +0200)
(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>
16 files changed:
disk-utils/mkfs.cramfs.c
login-utils/last.c
login-utils/su-common.c
login-utils/sulogin.c
misc-utils/cal.c
misc-utils/rename.c
sys-utils/flock.c
sys-utils/hwclock.c
sys-utils/ipcrm.c
sys-utils/nsenter.c
sys-utils/unshare.c
term-utils/agetty.c
text-utils/hexdump-parse.c
text-utils/more.c
text-utils/pg.c
text-utils/ul.c

index f277aaf2300b52dae3beff0fed2d3bb06a56affd..77b4467e7a92d8ffb2686fbcd7d58f7df9c63b2a 100644 (file)
@@ -123,7 +123,7 @@ struct entry {
 #define CRAMFS_OFFSET_WIDTH 26
 
 /* Input status of 0 to print help and exit without an error. */
-static void
+static void __attribute__((__noreturn__))
 usage(int status) {
        FILE *stream = status ? stderr : stdout;
 
index f93ec7fbfcfe5561170b15357f3abec63924caf1..d230deb7c7735cc73e6750440ea2b6308588c1bd 100644 (file)
@@ -830,7 +830,7 @@ static void process_wtmp_file(const struct last_control *ctl,
                                        c = whydown;
                                quit = list(ctl, &ut, lastboot, c);
                        }
-                       /* FALLTHRU */
+                       /* fallthrough */
 
                case DEAD_PROCESS:
                        /*
index 0999795c8b7b503b8eb643b872264c62bc691ade..032d62f9feefd11b229a90972ab5c52a858bc999 100644 (file)
@@ -899,6 +899,7 @@ su_main (int argc, char **argv, int mode)
     /* fallthrough if -u <user> is not specified, then follow
      * traditional su(1) behavior
      */
+     /* fallthrough */
   case SU_MODE:
     if (optind < argc)
       new_user = argv[optind++];
index 2487838e7093e58c260670d0c0247d359fb71a31..72bba623a292414b4fee241796076d7f3166ca44 100644 (file)
@@ -267,11 +267,11 @@ static void tcfinal(struct console *con)
                break;
        case 1:                         /* odd parity */
                tio->c_cflag |= PARODD;
-               /* fall through */
+               /* fallthrough */
        case 2:                         /* even parity */
                tio->c_cflag |= PARENB;
                tio->c_iflag |= (INPCK | ISTRIP);
-               /* fall through */
+               /* fallthrough */
        case (1 | 2):                   /* no parity bit */
                tio->c_cflag &= ~CSIZE;
                tio->c_cflag |= CS7;
@@ -971,7 +971,6 @@ int main(int argc, char **argv)
                switch ((con->pid = fork())) {
                case 0:
                        mask_signal(SIGCHLD, SIG_DFL, NULL);
-                       /* fall through */
                nofork:
                        setup(con);
                        while (1) {
@@ -1024,7 +1023,7 @@ int main(int argc, char **argv)
                        exit(0);
                case -1:
                        warn(_("fork failed"));
-                       /* fall through */
+                       /* fallthrough */
                default:
                        break;
                }
index 604eb26a7675b629e3a058903a34270cb92813fe..86e159bfa14dbdf01b96be7161a7415a3bb765dc 100644 (file)
@@ -431,7 +431,7 @@ int main(int argc, char **argv)
                ctl.req.day = strtos32_or_err(*argv++, _("illegal day value"));
                if (ctl.req.day < 1 || DAYS_IN_MONTH < ctl.req.day)
                        errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), DAYS_IN_MONTH);
-               /* FALLTHROUGH */
+               /* fallthrough */
        case 2:
                if (isdigit(**argv))
                        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)
                        errx(EXIT_FAILURE, _("illegal month value: use 1-12"));
-               /* FALLTHROUGH */
+               /* fallthrough */
        case 1:
                ctl.req.year = strtos32_or_err(*argv++, _("illegal year value"));
                if (ctl.req.year < SMALLEST_YEAR)
index 65ac543ef5d0e99f85b33f819f865d2d7315f0d7..b06a2d969b3f5d00910ba1900dff17d7ff27a5d0 100644 (file)
@@ -189,7 +189,6 @@ int main(int argc, char **argv)
                        return EXIT_SUCCESS;
                case 'h':
                        usage(stdout);
-                       /* fallthrough */
                default:
                        errtryhelp(EXIT_FAILURE);
                }
index 8af1e8ade03703830f7014ed12d961b719d16e1a..50194bdb93e84399524f6715a69a57a6bde2125f 100644 (file)
@@ -305,7 +305,7 @@ int main(int argc, char *argv[])
                                if (open_flags & O_RDWR)
                                        break;
                        }
-                       /* go through */
+                       /* fallthrough */
                default:
                        /* Other errors */
                        if (filename)
index 6031460796dbc5f20c0f2ce2c59fa461af51213f..c76f25d2e3f59d3791dad785e3bcf20e7fc19407 100644 (file)
@@ -1209,7 +1209,8 @@ static void out_version(void)
  * fmt, ... ), show a usage information and terminate the program
  * 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;
        va_list ap;
index 0432b224f2f137eea689c41bec1896c63a88de27..5b71f7d813ef022d762c1582192c05434c8d50ef 100644 (file)
@@ -346,6 +346,7 @@ int main(int argc, char **argv)
                                ret++;
                                break;
                        }
+                       /* fallthrough */
                case 'm':
                        if (!iskey)
                                id = strtos32_or_err(optarg, _("failed to parse argument"));
@@ -359,6 +360,7 @@ int main(int argc, char **argv)
                                ret++;
                                break;
                        }
+                       /* fallthrough */
                case 'q':
                        if (!iskey)
                                id = strtos32_or_err(optarg, _("failed to parse argument"));
@@ -372,6 +374,7 @@ int main(int argc, char **argv)
                                ret++;
                                break;
                        }
+                       /* fallthrough */
                case 's':
                        if (!iskey)
                                id = strtos32_or_err(optarg, _("failed to parse argument"));
index afa1b9c50251f593edac48e8f0686c7dda4b9d38..6ad0b0fe0bb121afa0c63bb10c43c6aa67ba142e 100644 (file)
@@ -65,7 +65,7 @@ static struct namespace_file {
        { .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;
 
index bccd75f3a1a032c3510c42685a39df6f01ba7b71..6c5c2e2f93e1daf160f02de6c8f092a7153622ce 100644 (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;
 
index 93a3843c776e9963d831d34a2b48870dfdd674cb..938fa2f97baba0f260839994dc7131a064012161 100644 (file)
@@ -2041,12 +2041,12 @@ static void termio_final(struct options *op, struct termios *tp, struct chardata
        case 1:
                /* odd parity */
                tp->c_cflag |= PARODD;
-               /* do not break */
+               /* fallthrough */
        case 2:
                /* even parity */
                tp->c_cflag |= PARENB;
                tp->c_iflag |= INPCK | ISTRIP;
-               /* do not break */
+               /* fallthrough */
        case (1 | 2):
                /* no parity bit */
                tp->c_cflag &= ~CSIZE;
index c60a4d06b66dbf3b376a003583d9e4893d0cf3e4..2b2735bf737a14bf61d900acb28b505a53060fca 100644 (file)
@@ -351,7 +351,7 @@ isint:                              cs[3] = '\0';
                                        case 'A':
                                                endfu = fu;
                                                fu->flags |= F_IGNORE;
-                                               /* FALLTHROUGH */
+                                               /* fallthrough */
                                        case 'a':
                                                pr->flags = F_ADDRESS;
                                                ++p2;
index 72dd96bf4231f13648a1f0e1fe307700eb19930f..c0c2e8743ed5bc261ac367535f1a692f11c6033a 100644 (file)
@@ -1270,7 +1270,7 @@ int command(char *filename, register FILE *f)
                                break;
                        }
                        lastp++;
-                       /* fall through */
+                       /* fallthrough */
                case '/':
                        if (nlines == 0)
                                nlines++;
@@ -1368,7 +1368,7 @@ int command(char *filename, register FILE *f)
                                                (char *)0);
                                break;
                        }
-                       /* fall through */
+                       /* fallthrough */
                default:
                        if (dum_opt) {
                                kill_line();
@@ -2023,6 +2023,7 @@ int expand(char **outbuf, char *inbuf)
                                *outstr++ = *inpstr++;
                                break;
                        }
+                       /* fallthrough */
                default:
                        *outstr++ = c;
                }
index 1b9b8d7dd9ab013d359d761f67524d21dbc8a9c5..50fd3c37990d7426424edf03ccde1fbe4db95998 100644 (file)
@@ -659,7 +659,7 @@ static void prompt(long long pageno)
                                        break;
                                case SEARCH_FIN:
                                        state = SEARCH;
-                                       /* FALLTHRU */
+                                       /* fallthrough */
                                case SEARCH:
                                        if (cmd.cmdline[cmd.cmdlen - 1] == '\\') {
                                                escape = 1;
@@ -738,7 +738,7 @@ static void prompt(long long pageno)
                                        continue;
                                }
                                state = COUNT;
-                               /* FALLTHRU */
+                               /* fallthrough */
                        case COUNT:
                                break;
                        case ADDON_FIN:
index 3986b420609eb80c199797bcdc2310e03a16ec3a..736483ef481d90b4545e7d4ead1e31b9c2d2d7fd 100644 (file)
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
 
        default:
                warnx(_("trouble reading terminfo"));
-               /* fall through to ... */
+               /* fallthrough */
 
        case 0:
                if (tflag)
@@ -317,7 +317,7 @@ static void filter(FILE *f)
                        }
                        obuf[col].c_char = '_';
                        obuf[col].c_width = 1;
-                       /* fall through */
+                       /* fallthrough */
                case ' ':
                        setcol(col + 1);
                        continue;