]> www.infradead.org Git - mtd-utils.git/commitdiff
Mark or fix switch cases that fall through
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 21 Sep 2017 09:15:32 +0000 (11:15 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 2 Nov 2017 00:34:18 +0000 (01:34 +0100)
Now that C++17 introduced a special fallthrough keyword for
explicitly tagging switch cases that are supposed to fall
through, newer gcc versions also implement a feature request
from 2002 to warn about maybe unwanted fall-throughs in switch
cases in other languages (like C).

For C code, we can either add a gcc specific attribute at the
end of the switch case, or use a special comment that gcc checks
for, indicating that the fall-through behaviour is indeed
intended.

This patch adds a "/* fall-through */" comment at the end of
various case blocks to silence gcc warnings and in some cases
a break, where fall-through was probably not intended.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
misc-utils/flash_erase.c
misc-utils/mtd_debug.c
nand-utils/nanddump.c
tests/fs-tests/utils/fstest_monitor.c
ubi-utils/ubiblock.c

index 6db9fa3b6b77a511608ff41b21cf6f2c21e017b9..0c9449fa8ed44bc407f049d10c5f71cff88a2903 100644 (file)
@@ -155,8 +155,10 @@ int main(int argc, char *argv[])
        default:
        case 0:
                errmsg("no MTD device specified");
+               /* fall-through */
        case 1:
                errmsg("no start erase block specified");
+               /* fall-through */
        case 2:
                errmsg("no erase block count specified");
                error = 1;
index d90a96832cfe27e18f73ab362fab401ce84c0882..1fd68712e2e26666029c7ca261694852a17722fd 100644 (file)
@@ -272,6 +272,7 @@ static int showinfo(int fd)
                        break;
                case MTD_UBIVOLUME:
                        printf("MTD_UBIVOLUME");
+                       break;
                default:
                        printf("(unknown type - new MTD API maybe?)");
        }
index bebb48e0c4f496eaf50d99bd14533de7f02bc351..2f167bb37e206de16be060b118b7c33bcedf028b 100644 (file)
@@ -180,6 +180,7 @@ static void process_options(int argc, char * const argv[])
                                break;
                        case 'c':
                                canonical = true;
+                               /* fall-through */
                        case 'p':
                                pretty_print = true;
                                break;
index afb951b88f3e08fae7e7547f5786e5c170746951..db687c18c4ee033b52599ef22c956691d0549810 100644 (file)
@@ -131,6 +131,7 @@ static int parse_command_line(char *cmdline, int *pargc, char ***pargv)
                                        break;
                                }
                                state = 1;
+                               /* fall-through */
                        case 1: /* Not quoted */
                                if (c == '\\') {
                                        if (*p)
index 8e366789a88cbd44bc94eacbbd14840252d14202..71e60b6cdfab1d879f60eac991a83e04916b3235 100644 (file)
@@ -74,6 +74,7 @@ static int parse_opt(int argc, char * const argv[])
                switch (key) {
                case 'c':
                        args.create = 1;
+                       /* fall-through */
                case 'r':
                        args.node = optarg;
                        break;