From 73d605b0f759a2ff9f859f78f76098dcdb290d37 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 29 Jan 2013 17:38:15 -0500 Subject: Detect platforms where memset(0) doesn't set doubles to 0.0. This is allowed by the C statndard, which permits you to represent doubles any way you like, but in practice we have some code that assumes that memset() clears doubles in structs. Noticed as part of 7802 review; see 8081 for more info. --- configure.ac | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index f047ab9027..6c4a0792fe 100644 --- a/configure.ac +++ b/configure.ac @@ -1033,6 +1033,30 @@ if test "$tor_cv_null_is_zero" != no; then [Define to 1 iff memset(0) sets pointers to NULL]) fi +AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero, +[AC_RUN_IFELSE([AC_LANG_SOURCE( +[[#include +#include +#include +#ifdef HAVE_STDDEF_H +#include +#endif +int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2)); +return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])], + [tor_cv_dbl0_is_zero=yes], + [tor_cv_dbl0_is_zero=no], + [tor_cv_dbl0_is_zero=cross])]) + +if test "$tor_cv_dbl0_is_zero" = cross ; then + # Cross-compiling; let's hope that the target isn't raving mad. + AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.]) +fi + +if test "$tor_cv_dbl0_is_zero" != no; then + AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1, + [Define to 1 iff memset(0) sets doubles to 0.0]) +fi + # And what happens when we malloc zero? AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works, [AC_RUN_IFELSE([AC_LANG_SOURCE( -- cgit v1.2.3-54-g00ecf