From 2798276316bbfd89ce08f7d19040d42a6e51bbad Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Mon, 15 Sep 2025 07:44:54 +0200 Subject: [PATCH] add -Wno-unterminated-string-initialization Without this on some new compilers this raises a warning (or error with -Werror): const char hexchars[16] = "0123456789abcdef"; The alternative is to add __attribute__((nonstring)) at the various places that need it. But 1) that requires various ifdefs to support old compilers, and 2) This doesn't catch anything meaningful in our code anyway and the odds of it doing so seem slim. --- configure | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 3 +++ 2 files changed, 54 insertions(+) diff --git a/configure b/configure index d8c5f9f90..f0223e99d 100755 --- a/configure +++ b/configure @@ -6168,6 +6168,57 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wunterminated-string-initialization" >&5 +printf %s "checking whether C compiler accepts -Wunterminated-string-initialization... " >&6; } +if test ${ax_cv_check_cflags__Werror___Wunterminated_string_initialization+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -Werror -Wunterminated-string-initialization" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ax_cv_check_cflags__Werror___Wunterminated_string_initialization=yes +else $as_nop + ax_cv_check_cflags__Werror___Wunterminated_string_initialization=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS=$ax_check_save_flags +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror___Wunterminated_string_initialization" >&5 +printf "%s\n" "$ax_cv_check_cflags__Werror___Wunterminated_string_initialization" >&6; } +if test x"$ax_cv_check_cflags__Werror___Wunterminated_string_initialization" = xyes +then : + CFLAGS="$CFLAGS -Wno-unterminated-string-initialization" +else $as_nop + : +fi + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + if $CC --version | grep -q "clang version 3." then : CFLAGS="$CFLAGS -Wno-tautological-compare -Wno-pragmas" diff --git a/configure.ac b/configure.ac index 02cb2307d..25e4ed55a 100644 --- a/configure.ac +++ b/configure.ac @@ -260,6 +260,9 @@ check_cc_flag([-Wempty-body], [CFLAGS="$CFLAGS -Wno-empty-body"]) dnl This warns about all our hook calls - RunHook() and others check_cc_flag([-Wdeprecated-non-prototype], [CFLAGS="$CFLAGS -Wno-deprecated-non-prototype"]) +dnl This warns about const char hexchars[16] = "0123456789abcdef"; +check_cc_flag([-Wunterminated-string-initialization], [CFLAGS="$CFLAGS -Wno-unterminated-string-initialization"]) + dnl Yeah this old clang version is a bit problematic dnl (ships in Ubuntu 16.04 for example) dnl -Wtautological-compare has false positives