From 937aaf762a873f184d308744cb10ebfcdfc18ec1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 9 Dec 2021 03:49:59 +0200 Subject: [PATCH 27/43] Autotools: Add configure check for printf() format specifier for size_t See osdn #43357 Signed-off-by: Marko Lindqvist --- configure.ac | 2 ++ m4/compiler.m4 | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/configure.ac b/configure.ac index cc506d43eb..dbca961b89 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,8 @@ dnl Sed is needed for the configuration dnl of the clients, database setting and the mapimg toolkits. AC_PROG_SED +FC_SIZE_T_FORMAT + AC_CACHE_CHECK([can we call malloc(0)], [fc_cv_malloc_zero_ok], [ AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include diff --git a/m4/compiler.m4 b/m4/compiler.m4 index 110afd803c..5a5c38b421 100644 --- a/m4/compiler.m4 +++ b/m4/compiler.m4 @@ -127,3 +127,32 @@ elif test "x$qt_ver" = "xQt6" && test "x$HAVE_CXX17" = "x" ; then cxx_works=no fi ]) + +# Test suitability of a single printf() format specifier for +# size_t variables. Helper for FC_SIZE_T_FORMAT +# +# $1 - Format string +AC_DEFUN([_FC_SIZE_T_FORMAT_TEST], +[ +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], +[[ +size_t var = 0; +printf("$1", var);]])], [SIZE_T_PRINTF="$1"]) +]) + +# Find out proper printf() format specifier for size_t variables +AC_DEFUN([FC_SIZE_T_FORMAT], +[ + for fmt in "%zu" "%ld" "%lld" + do + if test "x$SIZE_T_PRINTF" = "x" ; then + _FC_SIZE_T_FORMAT_TEST([${fmt}]) + fi + done + + if test "x$SIZE_T_PRINTF" = "x" ; then + AC_MSG_ERROR([Cannot find correct printf format specifier for size_t]) + fi + + AC_DEFINE_UNQUOTED([SIZE_T_PRINTF], ["$SIZE_T_PRINTF"], [Format specifier for size_t]) +]) -- 2.33.0