diff mbox series

[5/5] lib/ipset.c: Fix a compilation failure when using --enable-debug

Message ID 20181216213039.399-6-oliver@uptheinter.net
State RFC
Delegated to: Jozsef Kadlecsik
Headers show
Series RFC: Add new ip/net,port,ip/net,port sets | expand

Commit Message

Oliver Smith Dec. 16, 2018, 9:30 p.m. UTC
When using GCC8.2, since --enable-debug treats warnings as errors, the
compiler detects that a switch/case is falling through.

Since the fallthrough is intentional, we apply the attribute to indicate
to the compiler that this is correct behaviour.

Signed-off-by: Oliver Smith <oliver@uptheinter.net>
---
 lib/ipset.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jozsef Kadlecsik Dec. 18, 2018, 12:28 p.m. UTC | #1
Hi,

On Sun, 16 Dec 2018, Oliver Smith wrote:

> When using GCC8.2, since --enable-debug treats warnings as errors, the
> compiler detects that a switch/case is falling through.
> 
> Since the fallthrough is intentional, we apply the attribute to indicate
> to the compiler that this is correct behaviour.

But that'd restrict us to compile with gcc 8.2 or above only. Backward 
compatibility must be taken care of in include/libipset/compat.h, like

#if defined(__GNUC__) && __GNUC__ >= 7
#define FALL_THROUGH __attribute__ ((fallthrough));
#else
#define FALL_THROUGH
#endif /* __GNUC__ >= 7 */

Also, I'm surprised that gcc warns only at this spot: there are a couple 
of other intentional (and documented thus) fall through cases. Those 
should be guarded as well.

Best regards,
Jozsef

> Signed-off-by: Oliver Smith <oliver@uptheinter.net>
> ---
>  lib/ipset.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/ipset.c b/lib/ipset.c
> index 4366e60..e5c7bda 100644
> --- a/lib/ipset.c
> +++ b/lib/ipset.c
> @@ -1208,6 +1208,7 @@ ipset_parse_argv(struct ipset *ipset, int oargc, char *oargv[])
>  				return ret;
>  		}
>  		/* Fall through to parse optional setname */
> +		__attribute__ ((fallthrough));
>  	case IPSET_CMD_DESTROY:
>  	case IPSET_CMD_FLUSH:
>  		/* Args: [setname] */
> -- 
> 2.19.2
> 
> 

-
E-mail  : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.mta.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
          H-1525 Budapest 114, POB. 49, Hungary
diff mbox series

Patch

diff --git a/lib/ipset.c b/lib/ipset.c
index 4366e60..e5c7bda 100644
--- a/lib/ipset.c
+++ b/lib/ipset.c
@@ -1208,6 +1208,7 @@  ipset_parse_argv(struct ipset *ipset, int oargc, char *oargv[])
 				return ret;
 		}
 		/* Fall through to parse optional setname */
+		__attribute__ ((fallthrough));
 	case IPSET_CMD_DESTROY:
 	case IPSET_CMD_FLUSH:
 		/* Args: [setname] */