summaryrefslogtreecommitdiff
path: root/src/mpfr-impl.h
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-03-26 09:35:25 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-03-26 09:35:25 +0000
commitdd2f5ce2819f46468198de5876929ef90841df68 (patch)
treeaae52a8c6b73f0b88887fc67a54ef62196dd79f4 /src/mpfr-impl.h
parenta97e8495e7f14f33662f92f61abe6e95194830ce (diff)
downloadmpfr-dd2f5ce2819f46468198de5876929ef90841df68.tar.gz
[src/mpfr-impl.h] Bug fix (MPFR_ZEXP(x) as used for an assignment
could yield undefined behavior on platforms where mpfr_exp_t has trap representations); this is also a general improvement. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13821 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/mpfr-impl.h')
-rw-r--r--src/mpfr-impl.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h
index cb7c752a5..579368ff7 100644
--- a/src/mpfr-impl.h
+++ b/src/mpfr-impl.h
@@ -2589,11 +2589,14 @@ __MPFR_DECLSPEC mpfr_exp_t mpfr_ubf_diff_exp (mpfr_srcptr, mpfr_srcptr);
For practical reasons, the type of the argument x can be either
mpfr_ubf_ptr or mpfr_ptr, since the latter is used in functions
that accept both MPFR numbers and UBF's; this is checked by the
- code "(x)->_mpfr_exp".
+ code "(x)->_mpfr_exp" (the "sizeof" prevents an access, which
+ could be invalid when MPFR_ZEXP(x) is used for an assignment,
+ and also avoids breaking the aliasing rules if they are dealt
+ with in the future).
This macro can be used when building a UBF. So we do not check
that the _mpfr_exp field has the value MPFR_EXP_UBF. */
#define MPFR_ZEXP(x) \
- ((void) (x)->_mpfr_exp, \
+ ((void) sizeof ((x)->_mpfr_exp), \
((mpfr_ubf_ptr) (x))->_mpfr_zexp)
/* If x is a UBF, clear its mpz_t exponent. */