Commit 73d605b0 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

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.
parent a0351311
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.
......@@ -1033,6 +1033,30 @@ if test "$tor_cv_null_is_zero" != no; then
[Define to 1 iff memset(0) sets pointers to NULL])
AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
[[#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>
int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
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.])
if test "$tor_cv_dbl0_is_zero" != no; then
[Define to 1 iff memset(0) sets doubles to 0.0])
# And what happens when we malloc zero?
AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
......@@ -74,6 +74,11 @@
#error "It seems your platform does not represent NULL as zero. We can't cope."
#error "It seems your platform does not represent 0.0 as zeros. We can't cope."
#if 'a'!=97 || 'z'!=122 || 'A'!=65 || ' '!=32
#error "It seems that you encode characters in something other than ASCII."
......@@ -151,6 +151,9 @@
/* Define to 1 iff NULL is represented by a 0 in memory. */
/* Define to 1 iff memset(0) sets doubles to 0.0 */
/* Name of package */
#define PACKAGE "tor"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment