]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Detect platforms where memset(0) doesn't set doubles to 0.0.
authorNick Mathewson <nickm@torproject.org>
Tue, 29 Jan 2013 22:38:15 +0000 (17:38 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 29 Jan 2013 22:38:15 +0000 (17:38 -0500)
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.

changes/double-0-check [new file with mode: 0644]
configure.ac
src/common/compat.h
src/win32/orconfig.h

diff --git a/changes/double-0-check b/changes/double-0-check
new file mode 100644 (file)
index 0000000..74554cd
--- /dev/null
@@ -0,0 +1,8 @@
+  o Build improvements (bizarre platform detection):
+    - Try to detect it if we are ever building on a platform where
+      memset(...,0,...) does not set the value of a double to 0.0.  Such
+      platforms are permitted by the C standard, though in practice
+      they're pretty rare (since IEEE 754 is nigh-ubiquitous). We don't
+      currently support them, but it's better to detect them and fail
+      than to perform erroneously.
+
index f047ab9027908911bc6be9e4f8ba51eac5e1dd0b..6c4a0792fee1c7837524324b19750fc73887f33e 100644 (file)
@@ -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(
index 25293a4ed64df482d8b40318148e4a44acc609bd..b036419718b300a40fb4b318bbc184b6bf7c8d5c 100644 (file)
 #error "It seems your platform does not represent NULL as zero. We can't cope."
 #endif
 
+#ifndef DOUBLE_0_REP_IS_ZERO_BYTES
+#error "It seems your platform does not represent 0.0 as zeros. We can't cope."
+#endif
+
+
 #if 'a'!=97 || 'z'!=122 || 'A'!=65 || ' '!=32
 #error "It seems that you encode characters in something other than ASCII."
 #endif
index 6e45a2928b32a3068967879475b6814eda036d3b..ef08fdb2befc3a8e90fa077fd70c46d9b07802de 100644 (file)
 /* Define to 1 iff NULL is represented by a 0 in memory. */
 #define NULL_REP_IS_ZERO_BYTES 1
 
+/* Define to 1 iff memset(0) sets doubles to 0.0 */
+#define DOUBLE_0_REP_IS_ZERO_BYTES 1
+
 /* Name of package */
 #define PACKAGE "tor"