From b183a3ea7abed1d862be119fd8014dcf8fba5509 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 28 May 2022 18:12:24 +0200 Subject: [PATCH] Add -Wno-format-overflow as unfortunately this option is too dumb. Eg it warns on sprintf() usage even if there is a strlen() check right above it. Fixes compile warning on Ubuntu 22.04 / GCC 11. --- configure | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 ++ 2 files changed, 50 insertions(+) diff --git a/configure b/configure index 28f159b02..7bf94e732 100755 --- a/configure +++ b/configure @@ -5638,6 +5638,54 @@ 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 + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wformat-overflow" >&5 +$as_echo_n "checking whether C compiler accepts -Wformat-overflow... " >&6; } +if ${ax_cv_check_cflags__Werror___Wformat_overflow+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -Werror -Wformat-overflow" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ax_cv_check_cflags__Werror___Wformat_overflow=yes +else + ax_cv_check_cflags__Werror___Wformat_overflow=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS=$ax_check_save_flags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror___Wformat_overflow" >&5 +$as_echo "$ax_cv_check_cflags__Werror___Wformat_overflow" >&6; } +if test x"$ax_cv_check_cflags__Werror___Wformat_overflow" = xyes; then : + CFLAGS="$CFLAGS -Wno-format-overflow" +else + : +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 + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/configure.ac b/configure.ac index 9760e7cae..9749b841e 100644 --- a/configure.ac +++ b/configure.ac @@ -237,6 +237,8 @@ check_cc_flag([-Wformat-zero-length], [CFLAGS="$CFLAGS -Wno-format-zero-length"] check_cc_flag([-Wformat-truncation], [CFLAGS="$CFLAGS -Wno-format-truncation"]) +check_cc_flag([-Wformat-overflow], [CFLAGS="$CFLAGS -Wno-format-overflow"]) + dnl While it can be useful to occasionally to compile with warnings about dnl unused variables and parameters, we often 'think ahead' when coding things dnl so they may be useless now but not later. Similarly, for variables, we