Author: cazfi
Date: Tue Apr 12 23:00:01 2016
New Revision: 32371

URL: http://svn.gna.org/viewcvs/freeciv?rev=32371&view=rev
Log:
Added FC_STATIC_STRLEN configure test and use it's results instead of blindly 
trusting
that strlen() is acceptable as part of static assert in any situation.

See patch #7093

Modified:
    trunk/configure.ac
    trunk/gen_headers/freeciv_config.h.in
    trunk/m4/c11.m4
    trunk/server/savegame3.c
    trunk/utility/log.h

Modified: trunk/configure.ac
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/configure.ac?rev=32371&r1=32370&r2=32371&view=diff
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Tue Apr 12 23:00:01 2016
@@ -693,6 +693,8 @@
 
 FC_C11_STATIC_ASSERT
 FC_C11_AT_QUICK_EXIT
+
+FC_STATIC_STRLEN
 
 FC_CXX11_STATIC_ASSERT
 FC_CXX11_NULLPTR

Modified: trunk/gen_headers/freeciv_config.h.in
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/gen_headers/freeciv_config.h.in?rev=32371&r1=32370&r2=32371&view=diff
==============================================================================
--- trunk/gen_headers/freeciv_config.h.in       (original)
+++ trunk/gen_headers/freeciv_config.h.in       Tue Apr 12 23:00:01 2016
@@ -137,6 +137,9 @@
 /* C11 static assert supported */
 #undef FREECIV_C11_STATIC_ASSERT
 
+/* strlen() in static assert supported */
+#undef FREECIV_STATIC_STRLEN
+
 /* C++11 static assert supported */
 #undef FREECIV_CXX11_STATIC_ASSERT
 

Modified: trunk/m4/c11.m4
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/m4/c11.m4?rev=32371&r1=32370&r2=32371&view=diff
==============================================================================
--- trunk/m4/c11.m4     (original)
+++ trunk/m4/c11.m4     Tue Apr 12 23:00:01 2016
@@ -10,6 +10,22 @@
 [ac_cv_c11_static_assert=yes], [ac_cv_c11_static_assert=no])])
   if test "x${ac_cv_c11_static_assert}" = "xyes" ; then
     AC_DEFINE([FREECIV_C11_STATIC_ASSERT], [1], [C11 static assert supported])
+  fi
+])
+
+AC_DEFUN([FC_STATIC_STRLEN],
+[
+  AC_REQUIRE([FC_C11_STATIC_ASSERT])
+  if test "x${ac_cv_c11_static_assert}" = "xyes" ; then
+    AC_CACHE_CHECK([for strlen() usability in static assert], 
[ac_cv_static_strlen],
+      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <assert.h>
+#include <string.h>
+static const char str[] = "12345";
+]], [[_Static_assert(5 == strlen(str), "Wrong length"); ]])],
+[ac_cv_static_strlen=yes], [ac_cv_static_strlen=no])])
+    if test "x${ac_cv_static_strlen}" = "xyes" ; then
+      AC_DEFINE([FREECIV_STATIC_STRLEN], [1], [strlen() in static assert 
supported])
+    fi
   fi
 ])
 

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=32371&r1=32370&r2=32371&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Tue Apr 12 23:00:01 2016
@@ -5751,8 +5751,8 @@
         case ORDER_PERFORM_ACTION:
           action_buf[j] = num2char(punit->orders.list[j].action);
           /* Encoding with num2char() limits the number of actions. */
-          FC_STATIC_ASSERT(ACTION_COUNT <= strlen(num_chars),
-                           can_not_encode_all_actions);
+          FC_STATIC_STRLEN_ASSERT(ACTION_COUNT <= strlen(num_chars),
+                                  can_not_encode_all_actions);
 
           tgt_vec[j] = punit->orders.list[j].target;
           if (direction8_is_valid(punit->orders.list[j].dir)) {

Modified: trunk/utility/log.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/log.h?rev=32371&r1=32370&r2=32371&view=diff
==============================================================================
--- trunk/utility/log.h (original)
+++ trunk/utility/log.h Tue Apr 12 23:00:01 2016
@@ -207,6 +207,11 @@
 #ifdef FREECIV_C11_STATIC_ASSERT
 #define FC_STATIC_ASSERT(cond, tag) _Static_assert(cond, #tag)
 #endif /* FREECIV_C11_STATIC_ASSERT */
+#ifdef FREECIV_STATIC_STRLEN
+#define FC_STATIC_STRLEN_ASSERT(cond, tag) FC_STATIC_ASSERT(cond, tag)
+#else  /* FREECIV_STATIC_STRLEN */
+#define FC_STATIC_STRLEN_ASSERT(cond, tag)
+#endif /* FREECIV_STATIC_STRLEN */
 #endif /* __cplusplus */
 
 #ifndef FC_STATIC_ASSERT


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to