aboutsummaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-01-29 17:38:15 -0500
committerNick Mathewson <nickm@torproject.org>2013-01-29 17:38:15 -0500
commit73d605b0f759a2ff9f859f78f76098dcdb290d37 (patch)
tree6293cd558c73359e726a40c8d6157af08be7cd35 /configure.ac
parenta0351311aeea715cea24e156e065b65cc29a804c (diff)
downloadtor-73d605b0f759a2ff9f859f78f76098dcdb290d37.tar
tor-73d605b0f759a2ff9f859f78f76098dcdb290d37.tar.gz
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.
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac24
1 files changed, 24 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index f047ab902..6c4a0792f 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 <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#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(