From: Luis Chamberlain <mcgrof@kernel.org>
To: raymond.barbiero.dev@gmail.com
Cc: fstests@vger.kernel.org, jack@suse.cz,
mgorman@techsingularity.net, dave@stgolabs.net,
Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 09/25] snprintf: specify safe fallthrough on switches
Date: Wed, 9 Feb 2022 14:25:54 -0800 [thread overview]
Message-ID: <20220209222610.438470-10-mcgrof@kernel.org> (raw)
In-Reply-To: <20220209222610.438470-1-mcgrof@kernel.org>
gcc -Wall will complain when we fallthrough on a switch
but don't mean it. Fortunately we can follow the Linux kernel
strategy to use -Wimplicit-fallthrough=2 and allow comments
to supress this to clarify this was intended.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
Makefile.in | 4 +++-
snprintf.c | 3 +++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Makefile.in b/Makefile.in
index da2fc96..ef414a5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -16,6 +16,8 @@ DESTDIR=/
CC=@CC@
CFLAGS=@CFLAGS@ -I. -DVERSION=\"$(VERSION)\" -DDATADIR=\"$(datadir)\"
CFLAGS+=`pkg-config --cflags libtirpc`
+# Allows comments to be used for fallthrough
+CFLAGS+=-Wimplicit-fallthrough=2
CFLAGS_RPCGEN=-Wno-unused-variable
LIBS+=`pkg-config --libs libtirpc`
EXEEXT=@EXEEXT@
@@ -28,7 +30,7 @@ SRV_OBJS = util.o tbench_srv.o socklib.o
all: dbench doc
dbench: $(DB_OBJS)
- $(CC) -o $@ $(DB_OBJS) $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $(DB_OBJS) $(LIBS)
tbench_srv: $(SRV_OBJS)
$(CC) -o $@ $(SRV_OBJS) $(LIBS)
diff --git a/snprintf.c b/snprintf.c
index adfd3c4..9cfc20e 100644
--- a/snprintf.c
+++ b/snprintf.c
@@ -317,6 +317,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
break;
case 'X':
flags |= DP_F_UP;
+ /* fallthrough */
case 'x':
flags |= DP_F_UNSIGNED;
if (cflags == DP_C_SHORT)
@@ -339,6 +340,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
break;
case 'E':
flags |= DP_F_UP;
+ /* fallthrough */
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
@@ -348,6 +350,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
break;
case 'G':
flags |= DP_F_UP;
+ /* fallthrough */
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
--
2.34.1
next prev parent reply other threads:[~2022-02-09 22:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 22:25 [PATCH 00/25] dbench: fix compile warnings and update a bit Luis Chamberlain
2022-02-09 22:25 ` [PATCH 01/25] dbench: simplify open_loadfile() as check_loadfile_ok() Luis Chamberlain
2022-02-09 22:25 ` [PATCH 02/25] child: fix usage of gzFile and gzopen() Luis Chamberlain
2022-02-09 22:25 ` [PATCH 03/25] dbench: remove unused double t value Luis Chamberlain
2022-02-09 22:25 ` [PATCH 04/25] child: fix data type comparison on child_run Luis Chamberlain
2022-02-09 22:25 ` [PATCH 05/25] Makefile.in: disable unused warning for rpc generated code Luis Chamberlain
2022-02-09 22:25 ` [PATCH 06/25] configure.ac: run autoupdate Luis Chamberlain
2022-02-09 22:25 ` [PATCH 07/25] dbench: update use of time.h or sys/time.h Luis Chamberlain
2022-02-09 22:25 ` [PATCH 08/25] config.h.in: run autoconf Luis Chamberlain
2022-02-09 22:25 ` Luis Chamberlain [this message]
2022-02-09 22:25 ` [PATCH 10/25] nfsio.c: include dbench.h before nfs.h Luis Chamberlain
2022-02-09 22:25 ` [PATCH 11/25] nfsio: remove unused status variable Luis Chamberlain
2022-02-09 22:25 ` [PATCH 12/25] child: be expicit about string truncation goal Luis Chamberlain
2022-02-09 22:25 ` [PATCH 13/25] child: do not overlap on memcpy() Luis Chamberlain
2022-02-09 22:25 ` [PATCH 14/25] dbench.h: use bits/types.h instead of defining uint32 Luis Chamberlain
2022-02-09 22:26 ` [PATCH 15/25] sockio.c: use uint32_t Luis Chamberlain
2022-02-09 22:26 ` [PATCH 16/25] libnfs.c: fix a few simple compile warnings Luis Chamberlain
2022-02-09 22:26 ` [PATCH 17/25] libnfs: fix compilation warning for inet_tons Luis Chamberlain
2022-02-09 22:26 ` [PATCH 18/25] libnfs.c: fix sign conflict compile warning Luis Chamberlain
2022-02-09 22:26 ` [PATCH 19/25] Makefile.in: Luis Chamberlain
2022-02-09 22:26 ` [PATCH 20/25] linux_scsi.c: fix redeclaration of _GNU_SOURCE Luis Chamberlain
2022-02-09 22:26 ` [PATCH 21/25] Makefile.in: modernize build output with V=1 or V=0 Luis Chamberlain
2022-02-09 22:26 ` [PATCH 22/25] Makefile.in: declare datarootdir Luis Chamberlain
2022-02-09 22:26 ` [PATCH 23/25] configure.ac: fix smbclient detection Luis Chamberlain
2022-02-09 22:26 ` [PATCH 24/25] libiscsi: fix compile warning on data types Luis Chamberlain
2022-02-09 22:26 ` [PATCH 25/25] smb: fix compilation and disable warning on deprecated-declarations Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220209222610.438470-10-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=dave@stgolabs.net \
--cc=fstests@vger.kernel.org \
--cc=jack@suse.cz \
--cc=mgorman@techsingularity.net \
--cc=raymond.barbiero.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).