From 462619690769addb27d957077acd63c0999868cb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 4 Oct 2015 15:52:20 +0100 Subject: [PATCH] Eliminated reinterpret_casts. Partially fixes #24, #229. --- src/util/hwf.cpp | 7 ++++--- src/util/mpfx.cpp | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/hwf.cpp b/src/util/hwf.cpp index 21f1c281f..0c1e2d3de 100644 --- a/src/util/hwf.cpp +++ b/src/util/hwf.cpp @@ -85,8 +85,9 @@ hwf_manager::~hwf_manager() { } -#define RAW(X) (*reinterpret_cast(&(X))) -#define DBL(X) (*reinterpret_cast(&(X))) +// #define RAW(X) (*reinterpret_cast(&(X))) +#define RAW(X) ({ uint64 tmp; memcpy(&tmp, &(X), sizeof(uint64)); tmp; }) +#define DBL(X) ({ double tmp; memcpy(&tmp, &(X), sizeof(double)); tmp; }) void hwf_manager::set(hwf & o, int value) { o.value = (double) value; @@ -166,7 +167,7 @@ void hwf_manager::set(hwf & o, bool sign, uint64 significand, int exponent) { uint64 raw = (sign?0x8000000000000000ull:0); raw |= (((uint64)exponent) + 1023) << 52; raw |= significand; - o.value = *reinterpret_cast(&raw); + memcpy(&o.value, &raw, sizeof(double)); } void hwf_manager::set(hwf & o, hwf const & x) { diff --git a/src/util/mpfx.cpp b/src/util/mpfx.cpp index c75a43046..f9a51ebd7 100644 --- a/src/util/mpfx.cpp +++ b/src/util/mpfx.cpp @@ -199,8 +199,9 @@ void mpfx_manager::set(mpfx & n, uint64 v) { else { allocate_if_needed(n); n.m_sign = 0; - unsigned * _v = reinterpret_cast(&v); unsigned * w = words(n); + unsigned * _v = 0; + memcpy(_v, &v, sizeof(unsigned*)); for (unsigned i = 0; i < m_total_sz; i++) w[i] = 0; w[m_frac_part_sz] = _v[0]; @@ -679,7 +680,8 @@ int64 mpfx_manager::get_int64(mpfx const & n) const { SASSERT(is_int64(n)); unsigned * w = words(n); w += m_frac_part_sz; - uint64 r = *reinterpret_cast(w); + uint64 r = 0; + memcpy(&r, w, sizeof(uint64)); if (r == 0x8000000000000000ull) { SASSERT(is_neg(n)); return INT64_MIN; @@ -693,7 +695,9 @@ uint64 mpfx_manager::get_uint64(mpfx const & n) const { SASSERT(is_uint64(n)); unsigned * w = words(n); w += m_frac_part_sz; - return *reinterpret_cast(w); + uint64 r = 0; + memcpy(&r, w, sizeof(uint64)); + return r; } template