commit 5d07bda6907d4a9ab9e70ddbeab256055db53b7d
parent ab1f4173e36ffd7e070f378603cfb90869afa404
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Thu, 24 Apr 2025 10:14:44 +0200
configure: improved check for format warnings
Diffstat:
| M | configure.ac | | | 61 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- |
1 file changed, 59 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -377,13 +377,70 @@ AS_CASE([${enable_build_type}],[debug|debugger],
MHD_CHECK_ADD_CC_CFLAG([-Wextra], [CFLAGS_ac])
MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wpedantic], [-pedantic])
MHD_CHECK_ADD_CC_CFLAG([-Wdouble-promotion], [CFLAGS_ac])
+ save_find_CFLAGS_ac="$CFLAGS_ac"
MHD_FIND_ADD_CC_CFLAG_IFELSE(
[
- # clang produce warning when string pointer is used as a format specifier for v*printf() function
- AS_VAR_IF([mhd_cv_cc_clang_based],["yes"],[MHD_CHECK_ADD_CC_CFLAG([-Wno-format-nonliteral], [CFLAGS_ac])])
+ AC_CACHE_CHECK([whether format warnings work with v*printf() functions],
+ [mhd_cv_wformat_works_vfprintf],
+ [
+ SAVE_ac_c_werror_flag="$ac_c_werror_flag"
+ ac_c_werror_flag="yes"
+ CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <stdarg.h>
+
+static int
+my_vprint (const char *fm, va_list ap)
+{
+ return vfprintf (stderr, fm, ap);
+}
+
+static int
+my_printf (const char *fm, ...)
+{
+ int res;
+ va_list vargs;
+ va_start (vargs, fm);
+ res = my_vprint(fm, vargs);
+ va_end (vargs);
+ return res;
+}
+
+int main(void)
+{
+ const char *pnt_str = "printf string\n";
+ return (0 < my_printf (pnt_str)) ? 0 : 5;
+}
+ ]]
+ )
+ ],
+ [mhd_cv_wformat_works_vfprintf="yes"],
+ [mhd_cv_wformat_works_vfprintf="no"]
+ )
+ CFLAGS="${user_CFLAGS}"
+ ac_c_werror_flag="$SAVE_ac_c_werror_flag"
+ ]
+ )
+ AS_VAR_IF([mhd_cv_wformat_works_vfprintf],["no"],
+ [
+ # Check whether "enable" flag is supported as "disable" flag could be silently
+ # accepted when the compiled code itself does not produce any warnings
+ MHD_CHECK_CC_CFLAG([-Wformat-nonliteral],[CFLAGS_ac],
+ [
+ MHD_CHECK_ADD_CC_CFLAG([-Wno-format-nonliteral],[CFLAGS_ac],
+ [],[CFLAGS_ac="$save_find_CFLAGS_ac"]
+ )
+ ],[CFLAGS_ac="$save_find_CFLAGS_ac"]
+ )
+ ]
+ )
],[],
[CFLAGS_ac], [-Wformat=2], [-Wformat]
)
+ AS_UNSET([save_find_CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wformat-overflow -Wformat-truncation -Wformat-security -Wformat-signedness], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-include-dirs -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wpointer-arith], [CFLAGS_ac])