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)
downloadopenssh-git-e526127cbd2f8ad88fb41229df0c9b850c722830.tar.gz
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 c0e120fe..9dacccb2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2110,6 +2110,29 @@ if test "x$ac_cv_func_snprintf" = "xyes" ; then
)
fi
+if test "x$ac_cv_func_snprintf" = "xyes" ; then
+ AC_MSG_CHECKING([whether snprintf understands %zu])
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[
+#include <sys/types.h>
+#include <stdio.h>
+ ]],
+ [[
+ size_t a = 1, b = 2;
+ char z[128];
+ snprintf(z, sizeof z, "%zu%zu", a, b);
+ exit(strcmp(z, "12"));
+ ]])],
+ [AC_MSG_RESULT([yes])],
+ [
+ AC_MSG_RESULT([no])
+ AC_DEFINE([BROKEN_SNPRINTF], [1],
+ [snprintf does not understand %zu])
+ ],
+ [ AC_MSG_WARN([cross compiling: Assuming working snprintf()]) ]
+ )
+fi
+
# We depend on vsnprintf returning the right thing on overflow: the
# number of characters it tried to create (as per SUSv3)
if test "x$ac_cv_func_vsnprintf" = "xyes" ; then