[PATCH] Add support for fall-through handling if the compiler supports it

Andreas Schneider asn at samba.org
Thu Mar 1 10:10:31 UTC 2018


On Wednesday, 28 February 2018 21:54:32 CET Andrew Bartlett via samba-
technical wrote:
> On Mon, 2018-02-26 at 11:23 +0100, Andreas Schneider wrote:
> > On Friday, 23 February 2018 19:07:44 CET Andrew Bartlett wrote:
> > > On Tue, 2018-02-20 at 17:32 +0100, Andreas Schneider via samba-
> > > 
> > > technical wrote:
> > > > Yes, that's true. I've addressed it in the attached patchset.
> > > 
> > > I tried to push this, but it failed autobuild on ldb.
> > > 
> > > Can you push it to github and make a pull request?  That will trigger a
> > > Travis CI job that should cover everything on 14.04.  (or do a private
> > > autobuild).
> > 
> > I've fixed it, the configure check for the attribute needed to be build
> > with '-Werror' to detect it correctly.
> > 
> > The latest rebased patchset is attached.
> > 
> > A travis CI run is in the following pull request:
> > https://github.com/samba-team/samba/pull/133
> > 
> > 
> > Thanks for the review.
> 
> Can you please split out or explain the logic changes in:
> 
> auth:credentials: Add FALL_THROUGH statements in credentials.c
>     
>     Signed-off-by: Andreas Schneider <asn at samba.org>
> 
> The rest look OK so far, but the eyes tend to glaze over after a almost
> 60 patches :-)

Thank you very much! I've splitted the change, see attached.


Cheers,


	Andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
Samba Team                             asn at samba.org
www.samba.org
-------------- next part --------------
>From 97390bb57a93ec06c89ea7c7b930042040c1aab3 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 26 Jul 2017 18:20:53 +0200
Subject: [PATCH 1/3] auth:credentials: Add FALL_THROUGH statements in
 credentials.c

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 auth/credentials/credentials.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
index 4f3042e3152..f9a6bc3b13e 100644
--- a/auth/credentials/credentials.c
+++ b/auth/credentials/credentials.c
@@ -1277,7 +1277,8 @@ _PUBLIC_ bool cli_credentials_parse_password_fd(struct cli_credentials *credenti
 				*++p = '\0'; /* advance p, and null-terminate pass */
 				break;
 			}
-			/* fall through */
+
+			FALL_THROUGH;
 		case 0:
 			if (p - pass) {
 				*p = '\0'; /* null-terminate it, just in case... */
-- 
2.16.2


>From 3350373feb898e217b0000bb902abf356d305dbd Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Thu, 1 Mar 2018 11:04:49 +0100
Subject: [PATCH 2/3] auth:credentials: Avoid an 'else' branch

This moves the 'return' statement to the end of the 'case' and makes clear
we leave here.

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 auth/credentials/credentials.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
index f9a6bc3b13e..4663185c979 100644
--- a/auth/credentials/credentials.c
+++ b/auth/credentials/credentials.c
@@ -1284,11 +1284,14 @@ _PUBLIC_ bool cli_credentials_parse_password_fd(struct cli_credentials *credenti
 				*p = '\0'; /* null-terminate it, just in case... */
 				p = NULL; /* then force the loop condition to become false */
 				break;
-			} else {
-				fprintf(stderr, "Error reading password from file descriptor %d: %s\n", fd, "empty password\n");
-				return false;
 			}
 
+			fprintf(stderr,
+				"Error reading password from file descriptor "
+				"%d: empty password\n",
+				fd);
+			return false;
+
 		default:
 			fprintf(stderr, "Error reading password from file descriptor %d: %s\n",
 					fd, strerror(errno));
-- 
2.16.2


>From 09782ccebf11def7b2b5984f2cb45ca22ada0431 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 26 Jul 2017 16:29:06 +0200
Subject: [PATCH 3/3] wafsamba: Build with -Wimplicit-fallthrough if supported

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index cc08e0d5c3d..35f4f36f61c 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -711,6 +711,8 @@ def SAMBA_CONFIG_H(conf, path=None):
                         testflags=True)
         conf.ADD_CFLAGS('-Werror=uninitialized -Wuninitialized',
                         testflags=True)
+        conf.ADD_CFLAGS('-Wimplicit-fallthrough',
+                        testflags=True)
 
         conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True)
         conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True)
-- 
2.16.2



More information about the samba-technical mailing list