summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2018-10-12 16:43:35 +1100
committerDarren Tucker <dtucker@dtucker.net>2018-10-12 16:43:35 +1100
commite526127cbd2f8ad88fb41229df0c9b850c722830 (patch)
tree75c38b21102ba2980c33e101fb4f4c018c78522a
parentcf39f875191708c5f2f1a3c1c9019f106e74aea3 (diff)
Check if snprintf understands %zu.
If the platforms snprintf and friends don't understand %zu, use the compat replacement. Prevents segfaults on those platforms.
-rw-r--r--configure.ac23
1 files changed, 23 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index c0e120fe9..9dacccb2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2110,6 +2110,29 @@ if test "x$ac_cv_func_snprintf" = "xyes" ; then
2110 ) 2110 )
2111fi 2111fi
2112 2112
2113if test "x$ac_cv_func_snprintf" = "xyes" ; then
2114 AC_MSG_CHECKING([whether snprintf understands %zu])
2115 AC_RUN_IFELSE(
2116 [AC_LANG_PROGRAM([[
2117#include <sys/types.h>
2118#include <stdio.h>
2119 ]],
2120 [[
2121 size_t a = 1, b = 2;
2122 char z[128];
2123 snprintf(z, sizeof z, "%zu%zu", a, b);
2124 exit(strcmp(z, "12"));
2125 ]])],
2126 [AC_MSG_RESULT([yes])],
2127 [
2128 AC_MSG_RESULT([no])
2129 AC_DEFINE([BROKEN_SNPRINTF], [1],
2130 [snprintf does not understand %zu])
2131 ],
2132 [ AC_MSG_WARN([cross compiling: Assuming working snprintf()]) ]
2133 )
2134fi
2135
2113# We depend on vsnprintf returning the right thing on overflow: the 2136# We depend on vsnprintf returning the right thing on overflow: the
2114# number of characters it tried to create (as per SUSv3) 2137# number of characters it tried to create (as per SUSv3)
2115if test "x$ac_cv_func_vsnprintf" = "xyes" ; then 2138if test "x$ac_cv_func_vsnprintf" = "xyes" ; then