summaryrefslogtreecommitdiff
path: root/patches/mpfr/3.0.1/120-rec_sqrt-carry.patch
blob: 0367d846a06077b347d8da9c4465fdd3ea49b353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
diff -Naurd mpfr-3.0.1-a/PATCHES mpfr-3.0.1-b/PATCHES
--- mpfr-3.0.1-a/PATCHES	2011-05-04 11:18:33.000000000 +0000
+++ mpfr-3.0.1-b/PATCHES	2011-05-04 11:18:33.000000000 +0000
@@ -0,0 +1 @@
+rec_sqrt-carry
diff -Naurd mpfr-3.0.1-a/VERSION mpfr-3.0.1-b/VERSION
--- mpfr-3.0.1-a/VERSION	2011-04-12 10:50:02.000000000 +0000
+++ mpfr-3.0.1-b/VERSION	2011-05-04 11:18:33.000000000 +0000
@@ -1 +1 @@
-3.0.1-p1
+3.0.1-p2
diff -Naurd mpfr-3.0.1-a/mpfr.h mpfr-3.0.1-b/mpfr.h
--- mpfr-3.0.1-a/mpfr.h	2011-04-12 10:50:02.000000000 +0000
+++ mpfr-3.0.1-b/mpfr.h	2011-05-04 11:18:33.000000000 +0000
@@ -27,7 +27,7 @@
 #define MPFR_VERSION_MAJOR 3
 #define MPFR_VERSION_MINOR 0
 #define MPFR_VERSION_PATCHLEVEL 1
-#define MPFR_VERSION_STRING "3.0.1-p1"
+#define MPFR_VERSION_STRING "3.0.1-p2"
 
 /* Macros dealing with MPFR VERSION */
 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff -Naurd mpfr-3.0.1-a/rec_sqrt.c mpfr-3.0.1-b/rec_sqrt.c
--- mpfr-3.0.1-a/rec_sqrt.c	2011-04-04 10:19:18.000000000 +0000
+++ mpfr-3.0.1-b/rec_sqrt.c	2011-05-04 11:18:33.000000000 +0000
@@ -375,20 +375,37 @@
       MPFR_ASSERTD(un == ln + 1 || un == ln + 2);
       /* the high un-ln limbs of u will overlap the low part of {x+ln,xn},
          we need to add or subtract the overlapping part {u + ln, un - ln} */
+      /* Warning! th may be 0, in which case the mpn_add_1 and mpn_sub_1
+         below (with size = th) mustn't be used. In such a case, the limb
+         (carry) will be 0, so that this is semantically a no-op, but if
+         mpn_add_1 and mpn_sub_1 are used, GMP (currently) still does a
+         non-atomic read/write in a place that is not always allocated,
+         with the possible consequences: a crash if the corresponding
+         address is not mapped, or (rather unlikely) memory corruption
+         if another process/thread writes at the same place; things may
+         be worse with future GMP versions. Hence the tests carry != 0. */
       if (neg == 0)
         {
           if (ln > 0)
             MPN_COPY (x, u, ln);
           cy = mpn_add (x + ln, x + ln, xn, u + ln, un - ln);
           /* add cu at x+un */
-          cy += mpn_add_1 (x + un, x + un, th, cu);
+          if (cu != 0)
+            {
+              MPFR_ASSERTD (th != 0);
+              cy += mpn_add_1 (x + un, x + un, th, cu);
+            }
         }
       else /* negative case */
         {
           /* subtract {u+ln, un-ln} from {x+ln,un} */
           cy = mpn_sub (x + ln, x + ln, xn, u + ln, un - ln);
           /* carry cy is at x+un, like cu */
-          cy = mpn_sub_1 (x + un, x + un, th, cy + cu); /* n - un = th */
+          if (cy + cu != 0)
+            {
+              MPFR_ASSERTD (th != 0);
+              cy = mpn_sub_1 (x + un, x + un, th, cy + cu); /* n - un = th */
+            }
           /* cy cannot be zero, since the most significant bit of Xh is 1,
              and the correction is bounded by 2^{-h+3} */
           MPFR_ASSERTD(cy == 0);
diff -Naurd mpfr-3.0.1-a/version.c mpfr-3.0.1-b/version.c
--- mpfr-3.0.1-a/version.c	2011-04-12 10:50:02.000000000 +0000
+++ mpfr-3.0.1-b/version.c	2011-05-04 11:18:33.000000000 +0000
@@ -25,5 +25,5 @@
 const char *
 mpfr_get_version (void)
 {
-  return "3.0.1-p1";
+  return "3.0.1-p2";
 }