1From 962e532099d10ee6ce5b4ce68537bc46595230c0 Mon Sep 17 00:00:00 2001 2From: Joshua Watt <Joshua.Watt@garmin.com> 3Date: Tue, 24 Nov 2020 08:30:13 -0600 4Subject: [PATCH] Fix implicit fallthrough warning 5 6Fixes a warning about an implicit fall through in a case statement 7(-Werror=implicit-fallthrough) with newer versions of GCC 8 9Upstream-Status: Submitted [https://github.com/gnosek/fcgiwrap/pull/54] 10Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com> 11--- 12 configure.ac | 3 + 13 fcgiwrap.c | 7 ++ 14 m4/ax_gcc_func_attribute.m4 | 242 ++++++++++++++++++++++++++++++++++++ 15 3 files changed, 252 insertions(+) 16 create mode 100644 m4/ax_gcc_func_attribute.m4 17 18diff --git a/configure.ac b/configure.ac 19index bb3674e..9ef517a 100644 20--- a/configure.ac 21+++ b/configure.ac 22@@ -3,6 +3,7 @@ 23 24 AC_PREREQ(2.61) 25 AC_INIT([fcgiwrap], [1.1.0], [root@localdomain.pl]) 26+AC_CONFIG_MACRO_DIRS([m4]) 27 AM_CFLAGS="-std=gnu99 -Wall -Wextra -Werror -pedantic" 28 if test x"$CFLAGS" = x""; then 29 AM_CFLAGS="$AM_CFLAGS -O2 -g3" 30@@ -62,5 +63,7 @@ AC_FUNC_MALLOC 31 AC_CHECK_FUNCS([strchr strdup strrchr]) 32 AC_CHECK_FUNCS([dup2 putenv select setenv strerror],, [AC_MSG_ERROR([seems as if your libraries don't provide an expected function])]) 33 34+AX_GCC_FUNC_ATTRIBUTE([fallthrough]) 35+ 36 AC_CONFIG_FILES([Makefile]) 37 AC_OUTPUT 38diff --git a/fcgiwrap.c b/fcgiwrap.c 39index b44d8aa..a83726b 100644 40--- a/fcgiwrap.c 41+++ b/fcgiwrap.c 42@@ -56,6 +56,12 @@ 43 #define UNIX_PATH_MAX 108 44 #endif 45 46+#ifdef HAVE_FUNC_ATTRIBUTE_FALLTHROUGH 47+#define FALLTHROUGH __attribute__ ((fallthrough)) 48+#else 49+#define FALLTHROUGH (void) 50+#endif 51+ 52 extern char **environ; 53 static char * const * inherited_environ; 54 static const char **allowed_programs; 55@@ -580,6 +586,7 @@ static void handle_fcgi_request(void) 56 execl(filename, filename, (void *)NULL); 57 cgi_error("502 Bad Gateway", "Cannot execute script", filename); 58 59+ FALLTHROUGH; 60 default: /* parent */ 61 close(pipe_in[0]); 62 close(pipe_out[1]); 63diff --git a/m4/ax_gcc_func_attribute.m4 b/m4/ax_gcc_func_attribute.m4 64new file mode 100644 65index 0000000..da2b1ac 66--- /dev/null 67+++ b/m4/ax_gcc_func_attribute.m4 68@@ -0,0 +1,242 @@ 69+# =========================================================================== 70+# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html 71+# =========================================================================== 72+# 73+# SYNOPSIS 74+# 75+# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) 76+# 77+# DESCRIPTION 78+# 79+# This macro checks if the compiler supports one of GCC's function 80+# attributes; many other compilers also provide function attributes with 81+# the same syntax. Compiler warnings are used to detect supported 82+# attributes as unsupported ones are ignored by default so quieting 83+# warnings when using this macro will yield false positives. 84+# 85+# The ATTRIBUTE parameter holds the name of the attribute to be checked. 86+# 87+# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>. 88+# 89+# The macro caches its result in the ax_cv_have_func_attribute_<attribute> 90+# variable. 91+# 92+# The macro currently supports the following function attributes: 93+# 94+# alias 95+# aligned 96+# alloc_size 97+# always_inline 98+# artificial 99+# cold 100+# const 101+# constructor 102+# constructor_priority for constructor attribute with priority 103+# deprecated 104+# destructor 105+# dllexport 106+# dllimport 107+# error 108+# externally_visible 109+# fallthrough 110+# flatten 111+# format 112+# format_arg 113+# gnu_format 114+# gnu_inline 115+# hot 116+# ifunc 117+# leaf 118+# malloc 119+# noclone 120+# noinline 121+# nonnull 122+# noreturn 123+# nothrow 124+# optimize 125+# pure 126+# sentinel 127+# sentinel_position 128+# unused 129+# used 130+# visibility 131+# warning 132+# warn_unused_result 133+# weak 134+# weakref 135+# 136+# Unsupported function attributes will be tested with a prototype 137+# returning an int and not accepting any arguments and the result of the 138+# check might be wrong or meaningless so use with care. 139+# 140+# LICENSE 141+# 142+# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com> 143+# 144+# Copying and distribution of this file, with or without modification, are 145+# permitted in any medium without royalty provided the copyright notice 146+# and this notice are preserved. This file is offered as-is, without any 147+# warranty. 148+ 149+#serial 12 150+ 151+AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ 152+ AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) 153+ 154+ AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ 155+ AC_LINK_IFELSE([AC_LANG_PROGRAM([ 156+ m4_case([$1], 157+ [alias], [ 158+ int foo( void ) { return 0; } 159+ int bar( void ) __attribute__(($1("foo"))); 160+ ], 161+ [aligned], [ 162+ int foo( void ) __attribute__(($1(32))); 163+ ], 164+ [alloc_size], [ 165+ void *foo(int a) __attribute__(($1(1))); 166+ ], 167+ [always_inline], [ 168+ inline __attribute__(($1)) int foo( void ) { return 0; } 169+ ], 170+ [artificial], [ 171+ inline __attribute__(($1)) int foo( void ) { return 0; } 172+ ], 173+ [cold], [ 174+ int foo( void ) __attribute__(($1)); 175+ ], 176+ [const], [ 177+ int foo( void ) __attribute__(($1)); 178+ ], 179+ [constructor_priority], [ 180+ int foo( void ) __attribute__((__constructor__(65535/2))); 181+ ], 182+ [constructor], [ 183+ int foo( void ) __attribute__(($1)); 184+ ], 185+ [deprecated], [ 186+ int foo( void ) __attribute__(($1(""))); 187+ ], 188+ [destructor], [ 189+ int foo( void ) __attribute__(($1)); 190+ ], 191+ [dllexport], [ 192+ __attribute__(($1)) int foo( void ) { return 0; } 193+ ], 194+ [dllimport], [ 195+ int foo( void ) __attribute__(($1)); 196+ ], 197+ [error], [ 198+ int foo( void ) __attribute__(($1(""))); 199+ ], 200+ [externally_visible], [ 201+ int foo( void ) __attribute__(($1)); 202+ ], 203+ [fallthrough], [ 204+ int foo( void ) {switch (0) { case 1: __attribute__(($1)); case 2: break ; }}; 205+ ], 206+ [flatten], [ 207+ int foo( void ) __attribute__(($1)); 208+ ], 209+ [format], [ 210+ int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); 211+ ], 212+ [gnu_format], [ 213+ int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2))); 214+ ], 215+ [format_arg], [ 216+ char *foo(const char *p) __attribute__(($1(1))); 217+ ], 218+ [gnu_inline], [ 219+ inline __attribute__(($1)) int foo( void ) { return 0; } 220+ ], 221+ [hot], [ 222+ int foo( void ) __attribute__(($1)); 223+ ], 224+ [ifunc], [ 225+ int my_foo( void ) { return 0; } 226+ static int (*resolve_foo(void))(void) { return my_foo; } 227+ int foo( void ) __attribute__(($1("resolve_foo"))); 228+ ], 229+ [leaf], [ 230+ __attribute__(($1)) int foo( void ) { return 0; } 231+ ], 232+ [malloc], [ 233+ void *foo( void ) __attribute__(($1)); 234+ ], 235+ [noclone], [ 236+ int foo( void ) __attribute__(($1)); 237+ ], 238+ [noinline], [ 239+ __attribute__(($1)) int foo( void ) { return 0; } 240+ ], 241+ [nonnull], [ 242+ int foo(char *p) __attribute__(($1(1))); 243+ ], 244+ [noreturn], [ 245+ void foo( void ) __attribute__(($1)); 246+ ], 247+ [nothrow], [ 248+ int foo( void ) __attribute__(($1)); 249+ ], 250+ [optimize], [ 251+ __attribute__(($1(3))) int foo( void ) { return 0; } 252+ ], 253+ [pure], [ 254+ int foo( void ) __attribute__(($1)); 255+ ], 256+ [sentinel], [ 257+ int foo(void *p, ...) __attribute__(($1)); 258+ ], 259+ [sentinel_position], [ 260+ int foo(void *p, ...) __attribute__(($1(1))); 261+ ], 262+ [returns_nonnull], [ 263+ void *foo( void ) __attribute__(($1)); 264+ ], 265+ [unused], [ 266+ int foo( void ) __attribute__(($1)); 267+ ], 268+ [used], [ 269+ int foo( void ) __attribute__(($1)); 270+ ], 271+ [visibility], [ 272+ int foo_def( void ) __attribute__(($1("default"))); 273+ int foo_hid( void ) __attribute__(($1("hidden"))); 274+ int foo_int( void ) __attribute__(($1("internal"))); 275+ int foo_pro( void ) __attribute__(($1("protected"))); 276+ ], 277+ [warning], [ 278+ int foo( void ) __attribute__(($1(""))); 279+ ], 280+ [warn_unused_result], [ 281+ int foo( void ) __attribute__(($1)); 282+ ], 283+ [weak], [ 284+ int foo( void ) __attribute__(($1)); 285+ ], 286+ [weakref], [ 287+ static int foo( void ) { return 0; } 288+ static int bar( void ) __attribute__(($1("foo"))); 289+ ], 290+ [ 291+ m4_warn([syntax], [Unsupported attribute $1, the test may fail]) 292+ int foo( void ) __attribute__(($1)); 293+ ] 294+ )], []) 295+ ], 296+ dnl GCC doesn't exit with an error if an unknown attribute is 297+ dnl provided but only outputs a warning, so accept the attribute 298+ dnl only if no warning were issued. 299+ [AS_IF([grep -- -Wattributes conftest.err], 300+ [AS_VAR_SET([ac_var], [no])], 301+ [AS_VAR_SET([ac_var], [yes])])], 302+ [AS_VAR_SET([ac_var], [no])]) 303+ ]) 304+ 305+ AS_IF([test yes = AS_VAR_GET([ac_var])], 306+ [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, 307+ [Define to 1 if the system has the `$1' function attribute])], []) 308+ 309+ AS_VAR_POPDEF([ac_var]) 310+]) 311-- 3122.29.2 313 314