|
Added
Link Here
|
| 1 |
From 0ce17bae34a6c54de31b126f969d3ddd72c6bc37 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Vincent Lefevre <vincent@vinc17.net> |
| 3 |
Date: Tue, 22 Nov 2022 16:33:00 +0100 |
| 4 |
Subject: [PATCH] Fix mpfr_custom_get_kind() macro bug. |
| 5 |
|
| 6 |
* src/mpfr.h: in the mpfr_custom_get_kind() macro, changed mpfr_ptr to |
| 7 |
mpfr_srcptr for _x to agree with the function prototype, in order to |
| 8 |
avoid a compilation failure of user code in some cases. This bug was |
| 9 |
introduced by commit 9f94e0311ed53d0c64d4fbca249d19cc4888027e, which |
| 10 |
introduced the temporary variable _x to avoid an incorrect number of |
| 11 |
evaluations of the x argument. |
| 12 |
* tests/tstckintc.c: improved the tests to detect this bug. |
| 13 |
|
| 14 |
This should fix mpfr bug #1. |
| 15 |
|
| 16 |
Bug initially reported by FX Coudert: |
| 17 |
https://github.com/CGAL/cgal/issues/7064 |
| 18 |
|
| 19 |
It affects Fedora Linux: |
| 20 |
https://bugzilla.redhat.com/show_bug.cgi?id=2144197 |
| 21 |
--- |
| 22 |
src/mpfr.h | 2 +- |
| 23 |
tests/tstckintc.c | 10 +++++++--- |
| 24 |
2 files changed, 8 insertions(+), 4 deletions(-) |
| 25 |
|
| 26 |
diff --git a/src/mpfr.h b/src/mpfr.h |
| 27 |
index 8c8bc08d9..44d9329e3 100644 |
| 28 |
--- src/mpfr.h |
| 29 |
+++ src/mpfr.h |
| 30 |
@@ -1064,7 +1064,7 @@ __MPFR_DECLSPEC int mpfr_total_order_p (mpfr_srcptr, mpfr_srcptr); |
| 31 |
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95 |
| 32 |
#define mpfr_custom_get_kind(x) \ |
| 33 |
__extension__ ({ \ |
| 34 |
- mpfr_ptr _x = (x); \ |
| 35 |
+ mpfr_srcptr _x = (x); \ |
| 36 |
_x->_mpfr_exp > __MPFR_EXP_INF ? \ |
| 37 |
(mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (_x) \ |
| 38 |
: _x->_mpfr_exp == __MPFR_EXP_INF ? \ |
| 39 |
diff --git a/tests/tstckintc.c b/tests/tstckintc.c |
| 40 |
index e95e81ef9..a0c4486fb 100644 |
| 41 |
--- tests/tstckintc.c |
| 42 |
+++ tests/tstckintc.c |
| 43 |
@@ -295,14 +295,16 @@ static void |
| 44 |
test_nan_inf_zero (void) |
| 45 |
{ |
| 46 |
mpfr_ptr val; |
| 47 |
+ mpfr_srcptr sval; /* for compilation error checking */ |
| 48 |
int sign; |
| 49 |
int kind; |
| 50 |
|
| 51 |
reset_stack (); |
| 52 |
|
| 53 |
val = new_mpfr (MPFR_PREC_MIN); |
| 54 |
+ sval = val; |
| 55 |
mpfr_set_nan (val); |
| 56 |
- kind = (mpfr_custom_get_kind) (val); |
| 57 |
+ kind = (mpfr_custom_get_kind) (sval); |
| 58 |
if (kind != MPFR_NAN_KIND) |
| 59 |
{ |
| 60 |
printf ("mpfr_custom_get_kind error: "); |
| 61 |
@@ -380,7 +382,8 @@ static long * |
| 62 |
dummy_set_si (long si) |
| 63 |
{ |
| 64 |
mpfr_t x; |
| 65 |
- long * r = dummy_new (); |
| 66 |
+ mpfr_srcptr px; /* for compilation error checking */ |
| 67 |
+ long *r = dummy_new (); |
| 68 |
int i1, i2, i3, i4, i5; |
| 69 |
|
| 70 |
/* Check that the type "void *" can be used, like with the function. |
| 71 |
@@ -405,7 +408,8 @@ dummy_set_si (long si) |
| 72 |
MPFR_ASSERTN (i5 == 1); |
| 73 |
|
| 74 |
mpfr_set_si (x, si, MPFR_RNDN); |
| 75 |
- r[0] = mpfr_custom_get_kind (x); |
| 76 |
+ px = x; |
| 77 |
+ r[0] = mpfr_custom_get_kind (px); |
| 78 |
|
| 79 |
/* Check that the type "void *" can be used in C, like with the function |
| 80 |
(forbidden in C++). Also check side effects. */ |
| 81 |
-- |
| 82 |
GitLab |
| 83 |
|