mirror of
https://https.git.savannah.gnu.org/git/findutils.git
synced 2026-01-26 15:39:06 +00:00
maint: avoid implicit-fallthrough warnings from GCC 7
Avoid the new warnings GCC 7 gives with the "-Werror=implicit-fallthrough=" compiler option. Since version 7, GCC requires fallthrough switch/cases to be marked by the appropriate attribute. * lib/system.h: Add new header file defining the FALLTHROUGH macro. * lib/Makefile.am (libfind_a_SOURCES): Reference it. * find/print.c (do_fprintf): Use the new macro. * xargs/xargs.c (read_line): Likewise. (xargs_do_exec): For error(3), GCC 7 doesn't know that the function does not return, and would complain about falling through into the following case. Temporarily add an abort call - this will be fixed with another commit.
This commit is contained in:
parent
3876904855
commit
05da1fa358
11
find/print.c
11
find/print.c
@ -44,6 +44,7 @@
|
||||
#include "xalloc.h"
|
||||
|
||||
/* find-specific headers. */
|
||||
#include "system.h"
|
||||
#include "defs.h"
|
||||
#include "print.h"
|
||||
|
||||
@ -951,13 +952,8 @@ do_fprintf (struct format_val *dest,
|
||||
checked_fprintf (dest, segment->text, g->gr_name);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Do nothing. */
|
||||
/*FALLTHROUGH*/
|
||||
}
|
||||
}
|
||||
/*FALLTHROUGH*/ /*...sometimes, so 'G' case.*/
|
||||
FALLTHROUGH; /*...sometimes, so 'G' case.*/
|
||||
|
||||
case 'G': /* GID number */
|
||||
/* UNTRUSTED, probably unexploitable */
|
||||
@ -1165,9 +1161,8 @@ do_fprintf (struct format_val *dest,
|
||||
checked_fprintf (dest, segment->text, p->pw_name);
|
||||
break;
|
||||
}
|
||||
/* else fallthru */
|
||||
}
|
||||
/* FALLTHROUGH*/ /* .. to case U */
|
||||
FALLTHROUGH; /* .. to case U */
|
||||
|
||||
case 'U': /* UID number */
|
||||
/* UNTRUSTED, probably unexploitable */
|
||||
|
||||
@ -56,7 +56,8 @@ libfind_a_SOURCES = \
|
||||
splitstring.c \
|
||||
splitstring.h \
|
||||
bugreports.c \
|
||||
bugreports.h
|
||||
bugreports.h \
|
||||
system.h
|
||||
|
||||
EXTRA_DIST = unused-result.h check-regexprops.sh
|
||||
SUFFIXES =
|
||||
|
||||
43
lib/system.h
Normal file
43
lib/system.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* system.h -- system-dependent definitions for findutils
|
||||
|
||||
Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if !defined SYSTEM_H
|
||||
# define SYSTEM_H
|
||||
|
||||
/* FALLTHROUGH
|
||||
* Since GCC7, the "-Werror=implicit-fallthrough=" option requires
|
||||
* fallthrough cases to be marked as such via:
|
||||
* __attribute__ ((__fallthrough__))
|
||||
* Usage:
|
||||
* switch (c)
|
||||
* {
|
||||
* case 1:
|
||||
* doOne();
|
||||
* FALLTHROUGH;
|
||||
* case 2:
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
#ifndef FALLTHROUGH
|
||||
# if __GNUC__ < 7
|
||||
# define FALLTHROUGH ((void) 0)
|
||||
# else
|
||||
# define FALLTHROUGH __attribute__ ((__fallthrough__))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_H */
|
||||
@ -67,6 +67,7 @@
|
||||
#include "bugreports.h"
|
||||
#include "findutils-version.h"
|
||||
#include "gcc-function-attributes.h"
|
||||
#include "system.h"
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
@ -904,7 +905,7 @@ read_line (void)
|
||||
if (ISSPACE (c))
|
||||
continue;
|
||||
state = NORM;
|
||||
/* aaahhhh.... */
|
||||
FALLTHROUGH; /* aaahhhh.... */
|
||||
|
||||
case NORM:
|
||||
if (c == '\n')
|
||||
@ -1277,6 +1278,9 @@ xargs_do_exec (struct buildcmd_control *ctl, void *usercontext, int argc, char *
|
||||
{
|
||||
case -1:
|
||||
error (EXIT_FAILURE, errno, _("cannot fork"));
|
||||
/* error(EXIT_FAILURE, ...) does not return, but tell GCC 7 that
|
||||
we don't fall through here; fixed with another commit. */
|
||||
abort();
|
||||
|
||||
case 0: /* Child. */
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user