From 0b241f76dee8d46d33bbbf3fc80ce581f0f676bf Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 7 Apr 2021 03:21:58 +0300 Subject: [PATCH 16/17] tcc: Return value even after exit() call Fixes tcc warnings like server/savegame/savegame2.c:1048:error: function might return no value: 'char2terrain' See osdn #41890 Signed-off-by: Marko Lindqvist --- Makefile.am | 1 + client/clinet.c | 2 ++ configure.ac | 3 +++ gen_headers/freeciv_config.h.in | 3 +++ m4/tcc.m4 | 25 +++++++++++++++++++++++++ server/ruleset.c | 2 ++ server/savegame.c | 3 +++ server/savegame2.c | 3 +++ utility/support.h | 6 ++++++ 9 files changed, 48 insertions(+) create mode 100644 m4/tcc.m4 diff --git a/Makefile.am b/Makefile.am index d02b7ebdf6..d1d2f2b959 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,6 +71,7 @@ EXTRA_DIST = autogen.sh \ m4/sdl2-client.m4 \ m4/sqlite3.m4 \ m4/sound.m4 \ + m4/tcc.m4 \ m4/vsnprintf.m4 \ m4/web-client.m4 \ m4/winsock2.m4 \ diff --git a/client/clinet.c b/client/clinet.c index b1667e6639..1b27aa58ec 100644 --- a/client/clinet.c +++ b/client/clinet.c @@ -529,6 +529,8 @@ double try_to_autoconnect(void) server_host, server_port, user_name, errbuf); exit(EXIT_FAILURE); } + + RETURN_VALUE_AFTER_EXIT(1.0); } /************************************************************************** diff --git a/configure.ac b/configure.ac index fca58bbac6..f8f4a0020e 100644 --- a/configure.ac +++ b/configure.ac @@ -1552,6 +1552,9 @@ CFLAGS="$EXTRA_DEBUG_CFLAGS $CFLAGS" CXXFLAGS="$EXTRA_DEBUG_CXXFLAGS $CXXFLAGS" LDFLAGS="$EXTRA_DEBUG_LDFLAGS $LDFLAGS" +dnl Check this when -Werror is already set, if we're going to set it +FC_VALUE_AFTER_EXIT + dnl Rebuild 'configure' whenever fc_version changes, if maintainer mode enabled. AC_SUBST([CONFIGURE_DEPENDENCIES], ["$CONFIGURE_DEPENDENCIES \$(top_srcdir)/fc_version"]) diff --git a/gen_headers/freeciv_config.h.in b/gen_headers/freeciv_config.h.in index da5c2e5f6a..0d50be215e 100644 --- a/gen_headers/freeciv_config.h.in +++ b/gen_headers/freeciv_config.h.in @@ -50,6 +50,9 @@ /* MagickWand version 7 API in use */ #undef FREECIV_MWAND7 +/* Returning a value is expected even after exit() call */ +#undef FREECIV_RETURN_VALUE_AFTER_EXIT + /* locale.h available */ #undef FREECIV_HAVE_LOCALE_H diff --git a/m4/tcc.m4 b/m4/tcc.m4 new file mode 100644 index 0000000000..3126f45568 --- /dev/null +++ b/m4/tcc.m4 @@ -0,0 +1,25 @@ +# Check for the presence of behavior usualy seen with tcc + +# Check if valure must be returned even after exit() +# +AC_DEFUN([FC_VALUE_AFTER_EXIT], +[ + AC_CACHE_CHECK([needs to return value after exit()], [ac_cv_value_after_exit], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +int func(void) +{ + exit(1); +}]], [])], [ac_cv_value_after_exit=no +AC_MSG_RESULT([not needed])], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +int func(void) +{ + exit(1); + return 0; +}]], [])], [ac_cv_value_after_exit=yes +AC_MSG_RESULT([needed])], [ac_cv_value_after_exit=unknown +AC_MSG_RESULT([unknown])])])]) + if test "x${ac_cv_value_after_exit}" = "xyes" ; then + AC_DEFINE([FREECIV_RETURN_VALUE_AFTER_EXIT], [1], [[Value must be returned even after exit()]]) + fi +]) diff --git a/server/ruleset.c b/server/ruleset.c index 8305a1b874..eaa0a42194 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -6975,6 +6975,8 @@ bool load_rulesets(const char *restore, bool act, bool buffer_script) /* Cannot load even default ruleset, we're in completely unusable state */ exit(EXIT_FAILURE); + + RETURN_VALUE_AFTER_EXIT(FALSE); } /************************************************************************** diff --git a/server/savegame.c b/server/savegame.c index 52f9cce329..7f1e5cc60c 100644 --- a/server/savegame.c +++ b/server/savegame.c @@ -281,7 +281,10 @@ static struct terrain *char2terrain(char ch) } terrain_type_iterate_end; log_fatal("Unknown terrain identifier '%c' in savegame.", ch); + exit(EXIT_FAILURE); + + RETURN_VALUE_AFTER_EXIT(NULL); } /**************************************************************************** diff --git a/server/savegame2.c b/server/savegame2.c index 923ac9fd74..14e7fb719e 100644 --- a/server/savegame2.c +++ b/server/savegame2.c @@ -1467,7 +1467,10 @@ static struct terrain *char2terrain(char ch) } terrain_type_iterate_end; log_fatal("Unknown terrain identifier '%c' in savegame.", ch); + exit(EXIT_FAILURE); + + RETURN_VALUE_AFTER_EXIT(NULL); } /**************************************************************************** diff --git a/utility/support.h b/utility/support.h index ba0e8a0b96..ef2d30ec71 100644 --- a/utility/support.h +++ b/utility/support.h @@ -114,6 +114,12 @@ typedef long int fc_errno; typedef int fc_errno; #endif +#ifdef FREECIV_RETURN_VALUE_AFTER_EXIT +#define RETURN_VALUE_AFTER_EXIT(_val_) return _val_ ; +#else +#define RETURN_VALUE_AFTER_EXIT(_val_) +#endif + int fc_strcasecmp(const char *str0, const char *str1); int fc_strncasecmp(const char *str0, const char *str1, size_t n); int fc_strncasequotecmp(const char *str0, const char *str1, size_t n); -- 2.30.2