The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / mpfr / 0001-patchlevel11.patch
1 From http://www.mpfr.org/mpfr-current/allpatches
2 Fixes CVE-2014-9474.
3
4 Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
5
6 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
7 --- mpfr-3.1.2-a/PATCHES        2013-09-26 10:52:52.000000000 +0000
8 +++ mpfr-3.1.2-b/PATCHES        2013-09-26 10:52:52.000000000 +0000
9 @@ -0,0 +1 @@
10 +exp_2
11 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
12 --- mpfr-3.1.2-a/VERSION        2013-03-13 15:37:28.000000000 +0000
13 +++ mpfr-3.1.2-b/VERSION        2013-09-26 10:52:52.000000000 +0000
14 @@ -1 +1 @@
15 -3.1.2
16 +3.1.2-p1
17 diff -Naurd mpfr-3.1.2-a/src/exp_2.c mpfr-3.1.2-b/src/exp_2.c
18 --- mpfr-3.1.2-a/src/exp_2.c    2013-03-13 15:37:28.000000000 +0000
19 +++ mpfr-3.1.2-b/src/exp_2.c    2013-09-26 10:52:52.000000000 +0000
20 @@ -204,7 +204,7 @@
21            for (k = 0; k < K; k++)
22              {
23                mpz_mul (ss, ss, ss);
24 -              exps <<= 1;
25 +              exps *= 2;
26                exps += mpz_normalize (ss, ss, q);
27              }
28            mpfr_set_z (s, ss, MPFR_RNDN);
29 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
30 --- mpfr-3.1.2-a/src/mpfr.h     2013-03-13 15:37:37.000000000 +0000
31 +++ mpfr-3.1.2-b/src/mpfr.h     2013-09-26 10:52:52.000000000 +0000
32 @@ -27,7 +27,7 @@
33  #define MPFR_VERSION_MAJOR 3
34  #define MPFR_VERSION_MINOR 1
35  #define MPFR_VERSION_PATCHLEVEL 2
36 -#define MPFR_VERSION_STRING "3.1.2"
37 +#define MPFR_VERSION_STRING "3.1.2-p1"
38  
39  /* Macros dealing with MPFR VERSION */
40  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
41 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
42 --- mpfr-3.1.2-a/src/version.c  2013-03-13 15:37:34.000000000 +0000
43 +++ mpfr-3.1.2-b/src/version.c  2013-09-26 10:52:52.000000000 +0000
44 @@ -25,5 +25,5 @@
45  const char *
46  mpfr_get_version (void)
47  {
48 -  return "3.1.2";
49 +  return "3.1.2-p1";
50  }
51 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
52 --- mpfr-3.1.2-a/PATCHES        2013-09-26 10:56:55.000000000 +0000
53 +++ mpfr-3.1.2-b/PATCHES        2013-09-26 10:56:55.000000000 +0000
54 @@ -0,0 +1 @@
55 +fits-smallneg
56 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
57 --- mpfr-3.1.2-a/VERSION        2013-09-26 10:52:52.000000000 +0000
58 +++ mpfr-3.1.2-b/VERSION        2013-09-26 10:56:55.000000000 +0000
59 @@ -1 +1 @@
60 -3.1.2-p1
61 +3.1.2-p2
62 diff -Naurd mpfr-3.1.2-a/src/fits_u.h mpfr-3.1.2-b/src/fits_u.h
63 --- mpfr-3.1.2-a/src/fits_u.h   2013-03-13 15:37:35.000000000 +0000
64 +++ mpfr-3.1.2-b/src/fits_u.h   2013-09-26 10:56:55.000000000 +0000
65 @@ -32,17 +32,20 @@
66    int res;
67  
68    if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
69 -    /* Zero always fit */
70 -    return MPFR_IS_ZERO (f) ? 1 : 0;
71 -  else if (MPFR_IS_NEG (f))
72 -    /* Negative numbers don't fit */
73 -    return 0;
74 -  /* now it fits if
75 -     (a) f <= MAXIMUM
76 -     (b) round(f, prec(slong), rnd) <= MAXIMUM */
77 +    return MPFR_IS_ZERO (f) ? 1 : 0;  /* Zero always fits */
78  
79    e = MPFR_GET_EXP (f);
80  
81 +  if (MPFR_IS_NEG (f))
82 +    return e >= 1 ? 0  /* f <= -1 does not fit */
83 +      : rnd != MPFR_RNDN ? MPFR_IS_LIKE_RNDU (rnd, -1)  /* directed mode */
84 +      : e < 0 ? 1  /* f > -1/2 fits in MPFR_RNDN */
85 +      : mpfr_powerof2_raw(f);  /* -1/2 fits, -1 < f < -1/2 don't */
86 +
87 +  /* Now it fits if
88 +     (a) f <= MAXIMUM
89 +     (b) round(f, prec(slong), rnd) <= MAXIMUM */
90 +
91    /* first compute prec(MAXIMUM); fits in an int */
92    for (s = MAXIMUM, prec = 0; s != 0; s /= 2, prec ++);
93  
94 diff -Naurd mpfr-3.1.2-a/src/fits_uintmax.c mpfr-3.1.2-b/src/fits_uintmax.c
95 --- mpfr-3.1.2-a/src/fits_uintmax.c     2013-03-13 15:37:33.000000000 +0000
96 +++ mpfr-3.1.2-b/src/fits_uintmax.c     2013-09-26 10:56:55.000000000 +0000
97 @@ -27,51 +27,19 @@
98  #include "mpfr-intmax.h"
99  #include "mpfr-impl.h"
100  
101 -#ifdef _MPFR_H_HAVE_INTMAX_T
102 -
103 -/* We can't use fits_u.h <= mpfr_cmp_ui */
104 -int
105 -mpfr_fits_uintmax_p (mpfr_srcptr f, mpfr_rnd_t rnd)
106 -{
107 -  mpfr_exp_t e;
108 -  int prec;
109 -  uintmax_t s;
110 -  mpfr_t x;
111 -  int res;
112 -
113 -  if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
114 -    /* Zero always fit */
115 -    return MPFR_IS_ZERO (f) ? 1 : 0;
116 -  else if (MPFR_IS_NEG (f))
117 -    /* Negative numbers don't fit */
118 -    return 0;
119 -  /* now it fits if
120 -     (a) f <= MAXIMUM
121 -     (b) round(f, prec(slong), rnd) <= MAXIMUM */
122 -
123 -  e = MPFR_GET_EXP (f);
124 -
125 -  /* first compute prec(MAXIMUM); fits in an int */
126 -  for (s = MPFR_UINTMAX_MAX, prec = 0; s != 0; s /= 2, prec ++);
127 -
128 -  /* MAXIMUM needs prec bits, i.e. MAXIMUM = 2^prec - 1 */
129 -
130 -  /* if e <= prec - 1, then f < 2^(prec-1) < MAXIMUM */
131 -  if (e <= prec - 1)
132 -    return 1;
133 +/* Note: though mpfr-impl.h is included in fits_u.h, we also include it
134 +   above so that it gets included even when _MPFR_H_HAVE_INTMAX_T is not
135 +   defined; this is necessary to avoid an empty translation unit, which
136 +   is forbidden by ISO C. Without this, a failing test can be reproduced
137 +   by creating an invalid stdint.h somewhere in the default include path
138 +   and by compiling MPFR with "gcc -ansi -pedantic-errors". */
139  
140 -  /* if e >= prec + 1, then f >= 2^prec > MAXIMUM */
141 -  if (e >= prec + 1)
142 -    return 0;
143 +#ifdef _MPFR_H_HAVE_INTMAX_T
144  
145 -  MPFR_ASSERTD (e == prec);
146 +#define FUNCTION   mpfr_fits_uintmax_p
147 +#define MAXIMUM    MPFR_UINTMAX_MAX
148 +#define TYPE       uintmax_t
149  
150 -  /* hard case: first round to prec bits, then check */
151 -  mpfr_init2 (x, prec);
152 -  mpfr_set (x, f, rnd);
153 -  res = MPFR_GET_EXP (x) == e;
154 -  mpfr_clear (x);
155 -  return res;
156 -}
157 +#include "fits_u.h"
158  
159  #endif
160 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
161 --- mpfr-3.1.2-a/src/mpfr.h     2013-09-26 10:52:52.000000000 +0000
162 +++ mpfr-3.1.2-b/src/mpfr.h     2013-09-26 10:56:55.000000000 +0000
163 @@ -27,7 +27,7 @@
164  #define MPFR_VERSION_MAJOR 3
165  #define MPFR_VERSION_MINOR 1
166  #define MPFR_VERSION_PATCHLEVEL 2
167 -#define MPFR_VERSION_STRING "3.1.2-p1"
168 +#define MPFR_VERSION_STRING "3.1.2-p2"
169  
170  /* Macros dealing with MPFR VERSION */
171  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
172 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
173 --- mpfr-3.1.2-a/src/version.c  2013-09-26 10:52:52.000000000 +0000
174 +++ mpfr-3.1.2-b/src/version.c  2013-09-26 10:56:55.000000000 +0000
175 @@ -25,5 +25,5 @@
176  const char *
177  mpfr_get_version (void)
178  {
179 -  return "3.1.2-p1";
180 +  return "3.1.2-p2";
181  }
182 diff -Naurd mpfr-3.1.2-a/tests/tfits.c mpfr-3.1.2-b/tests/tfits.c
183 --- mpfr-3.1.2-a/tests/tfits.c  2013-03-13 15:37:45.000000000 +0000
184 +++ mpfr-3.1.2-b/tests/tfits.c  2013-09-26 10:56:55.000000000 +0000
185 @@ -33,155 +33,176 @@
186  #include "mpfr-intmax.h"
187  #include "mpfr-test.h"
188  
189 -#define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
190 -#define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
191 +#define ERROR1(N)                                               \
192 +  do                                                            \
193 +    {                                                           \
194 +      printf("Error %d for rnd = %s and x = ", N,               \
195 +             mpfr_print_rnd_mode ((mpfr_rnd_t) r));             \
196 +      mpfr_dump(x);                                             \
197 +      exit(1);                                                  \
198 +    }                                                           \
199 +  while (0)
200  
201  static void check_intmax (void);
202  
203  int
204  main (void)
205  {
206 -  mpfr_t x;
207 +  mpfr_t x, y;
208 +  int i, r;
209  
210    tests_start_mpfr ();
211  
212    mpfr_init2 (x, 256);
213 +  mpfr_init2 (y, 8);
214  
215 -  /* Check NAN */
216 -  mpfr_set_nan (x);
217 -  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
218 -    ERROR1;
219 -  if (mpfr_fits_slong_p (x, MPFR_RNDN))
220 -    ERROR1;
221 -  if (mpfr_fits_uint_p (x, MPFR_RNDN))
222 -    ERROR1;
223 -  if (mpfr_fits_sint_p (x, MPFR_RNDN))
224 -    ERROR1;
225 -  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
226 -    ERROR1;
227 -  if (mpfr_fits_sshort_p (x, MPFR_RNDN))
228 -    ERROR1;
229 +  RND_LOOP (r)
230 +    {
231  
232 -  /* Check INF */
233 -  mpfr_set_inf (x, 1);
234 -  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
235 -    ERROR1;
236 -  if (mpfr_fits_slong_p (x, MPFR_RNDN))
237 -    ERROR1;
238 -  if (mpfr_fits_uint_p (x, MPFR_RNDN))
239 -    ERROR1;
240 -  if (mpfr_fits_sint_p (x, MPFR_RNDN))
241 -    ERROR1;
242 -  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
243 -    ERROR1;
244 -  if (mpfr_fits_sshort_p (x, MPFR_RNDN))
245 -    ERROR1;
246 +      /* Check NAN */
247 +      mpfr_set_nan (x);
248 +      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
249 +        ERROR1 (1);
250 +      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
251 +        ERROR1 (2);
252 +      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
253 +        ERROR1 (3);
254 +      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
255 +        ERROR1 (4);
256 +      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
257 +        ERROR1 (5);
258 +      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
259 +        ERROR1 (6);
260  
261 -  /* Check Zero */
262 -  MPFR_SET_ZERO (x);
263 -  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
264 -    ERROR2;
265 -  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
266 -    ERROR2;
267 -  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
268 -    ERROR2;
269 -  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
270 -    ERROR2;
271 -  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
272 -    ERROR2;
273 -  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
274 -    ERROR2;
275 +      /* Check INF */
276 +      mpfr_set_inf (x, 1);
277 +      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
278 +        ERROR1 (7);
279 +      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
280 +        ERROR1 (8);
281 +      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
282 +        ERROR1 (9);
283 +      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
284 +        ERROR1 (10);
285 +      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
286 +        ERROR1 (11);
287 +      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
288 +        ERROR1 (12);
289  
290 -  /* Check small op */
291 -  mpfr_set_str1 (x, "1@-1");
292 -  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
293 -    ERROR2;
294 -  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
295 -    ERROR2;
296 -  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
297 -    ERROR2;
298 -  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
299 -    ERROR2;
300 -  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
301 -    ERROR2;
302 -  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
303 -    ERROR2;
304 +      /* Check Zero */
305 +      MPFR_SET_ZERO (x);
306 +      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
307 +        ERROR1 (13);
308 +      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
309 +        ERROR1 (14);
310 +      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
311 +        ERROR1 (15);
312 +      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
313 +        ERROR1 (16);
314 +      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
315 +        ERROR1 (17);
316 +      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
317 +        ERROR1 (18);
318  
319 -  /* Check 17 */
320 -  mpfr_set_ui (x, 17, MPFR_RNDN);
321 -  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
322 -    ERROR2;
323 -  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
324 -    ERROR2;
325 -  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
326 -    ERROR2;
327 -  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
328 -    ERROR2;
329 -  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
330 -    ERROR2;
331 -  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
332 -    ERROR2;
333 +      /* Check small positive op */
334 +      mpfr_set_str1 (x, "1@-1");
335 +      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
336 +        ERROR1 (19);
337 +      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
338 +        ERROR1 (20);
339 +      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
340 +        ERROR1 (21);
341 +      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
342 +        ERROR1 (22);
343 +      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
344 +        ERROR1 (23);
345 +      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
346 +        ERROR1 (24);
347  
348 -  /* Check all other values */
349 -  mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
350 -  mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
351 -  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
352 -    ERROR1;
353 -  if (mpfr_fits_slong_p (x, MPFR_RNDN))
354 -    ERROR1;
355 -  mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
356 -  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
357 -    ERROR1;
358 -  if (mpfr_fits_uint_p (x, MPFR_RNDN))
359 -    ERROR1;
360 -  if (mpfr_fits_sint_p (x, MPFR_RNDN))
361 -    ERROR1;
362 -  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
363 -    ERROR1;
364 -  if (mpfr_fits_sshort_p (x, MPFR_RNDN))
365 -    ERROR1;
366 +      /* Check 17 */
367 +      mpfr_set_ui (x, 17, MPFR_RNDN);
368 +      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
369 +        ERROR1 (25);
370 +      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
371 +        ERROR1 (26);
372 +      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
373 +        ERROR1 (27);
374 +      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
375 +        ERROR1 (28);
376 +      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
377 +        ERROR1 (29);
378 +      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
379 +        ERROR1 (30);
380  
381 -  mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
382 -  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
383 -    ERROR2;
384 -  mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
385 -  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
386 -    ERROR2;
387 -  mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
388 -  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
389 -    ERROR2;
390 -  mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
391 -  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
392 -    ERROR2;
393 -  mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
394 -  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
395 -    ERROR2;
396 -  mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
397 -  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
398 -    ERROR2;
399 +      /* Check all other values */
400 +      mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
401 +      mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
402 +      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
403 +        ERROR1 (31);
404 +      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
405 +        ERROR1 (32);
406 +      mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
407 +      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
408 +        ERROR1 (33);
409 +      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
410 +        ERROR1 (34);
411 +      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
412 +        ERROR1 (35);
413 +      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
414 +        ERROR1 (36);
415 +      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
416 +        ERROR1 (37);
417  
418 -  mpfr_set_si (x, 1, MPFR_RNDN);
419 -  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
420 -    ERROR2;
421 -  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
422 -    ERROR2;
423 +      mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
424 +      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
425 +        ERROR1 (38);
426 +      mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
427 +      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
428 +        ERROR1 (39);
429 +      mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
430 +      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
431 +        ERROR1 (40);
432 +      mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
433 +      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
434 +        ERROR1 (41);
435 +      mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
436 +      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
437 +        ERROR1 (42);
438 +      mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
439 +      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
440 +        ERROR1 (43);
441  
442 -  /* Check negative value */
443 -  mpfr_set_si (x, -1, MPFR_RNDN);
444 -  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
445 -    ERROR2;
446 -  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
447 -    ERROR2;
448 -  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
449 -    ERROR2;
450 -  if (mpfr_fits_uint_p (x, MPFR_RNDN))
451 -    ERROR1;
452 -  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
453 -    ERROR1;
454 -  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
455 -    ERROR1;
456 +      mpfr_set_si (x, 1, MPFR_RNDN);
457 +      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
458 +        ERROR1 (44);
459 +      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
460 +        ERROR1 (45);
461 +
462 +      /* Check negative op */
463 +      for (i = 1; i <= 4; i++)
464 +        {
465 +          int inv;
466 +
467 +          mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
468 +          mpfr_rint (y, x, (mpfr_rnd_t) r);
469 +          inv = MPFR_NOTZERO (y);
470 +          if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r) ^ inv)
471 +            ERROR1 (46);
472 +          if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
473 +            ERROR1 (47);
474 +          if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r) ^ inv)
475 +            ERROR1 (48);
476 +          if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
477 +            ERROR1 (49);
478 +          if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r) ^ inv)
479 +            ERROR1 (50);
480 +          if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
481 +            ERROR1 (51);
482 +        }
483 +    }
484  
485    mpfr_clear (x);
486 +  mpfr_clear (y);
487  
488    check_intmax ();
489  
490 @@ -189,85 +210,98 @@
491    return 0;
492  }
493  
494 -static void check_intmax (void)
495 +static void
496 +check_intmax (void)
497  {
498  #ifdef _MPFR_H_HAVE_INTMAX_T
499 -  mpfr_t x;
500 +  mpfr_t x, y;
501 +  int i, r;
502  
503 -  mpfr_init2 (x, sizeof (uintmax_t)*CHAR_BIT);
504 +  mpfr_init2 (x, sizeof (uintmax_t) * CHAR_BIT);
505 +  mpfr_init2 (y, 8);
506  
507 -  /* Check NAN */
508 -  mpfr_set_nan (x);
509 -  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
510 -    ERROR1;
511 -  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
512 -    ERROR1;
513 +  RND_LOOP (r)
514 +    {
515 +      /* Check NAN */
516 +      mpfr_set_nan (x);
517 +      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
518 +        ERROR1 (52);
519 +      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
520 +        ERROR1 (53);
521  
522 -  /* Check INF */
523 -  mpfr_set_inf (x, 1);
524 -  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
525 -    ERROR1;
526 -  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
527 -    ERROR1;
528 +      /* Check INF */
529 +      mpfr_set_inf (x, 1);
530 +      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
531 +        ERROR1 (54);
532 +      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
533 +        ERROR1 (55);
534  
535 -  /* Check Zero */
536 -  MPFR_SET_ZERO (x);
537 -  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
538 -    ERROR2;
539 -  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
540 -    ERROR2;
541 +      /* Check Zero */
542 +      MPFR_SET_ZERO (x);
543 +      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
544 +        ERROR1 (56);
545 +      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
546 +        ERROR1 (57);
547  
548 -  /* Check small op */
549 -  mpfr_set_str1 (x, "1@-1");
550 -  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
551 -    ERROR2;
552 -  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
553 -    ERROR2;
554 +      /* Check positive small op */
555 +      mpfr_set_str1 (x, "1@-1");
556 +      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
557 +        ERROR1 (58);
558 +      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
559 +        ERROR1 (59);
560  
561 -  /* Check 17 */
562 -  mpfr_set_ui (x, 17, MPFR_RNDN);
563 -  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
564 -    ERROR2;
565 -  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
566 -    ERROR2;
567 +      /* Check 17 */
568 +      mpfr_set_ui (x, 17, MPFR_RNDN);
569 +      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
570 +        ERROR1 (60);
571 +      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
572 +        ERROR1 (61);
573  
574 -  /* Check hugest */
575 -  mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
576 -  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
577 -    ERROR1;
578 -  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
579 -    ERROR1;
580 +      /* Check hugest */
581 +      mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
582 +      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
583 +        ERROR1 (62);
584 +      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
585 +        ERROR1 (63);
586  
587 -  /* Check all other values */
588 -  mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
589 -  mpfr_add_ui (x, x, 1, MPFR_RNDN);
590 -  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
591 -    ERROR1;
592 -  mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
593 -  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
594 -    ERROR2;
595 -  mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
596 -  mpfr_add_ui (x, x, 1, MPFR_RNDN);
597 -  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
598 -    ERROR1;
599 -  mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
600 -  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
601 -    ERROR2;
602 -  mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
603 -  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
604 -    ERROR2;
605 -  mpfr_sub_ui (x, x, 1, MPFR_RNDN);
606 -  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
607 -    ERROR1;
608 +      /* Check all other values */
609 +      mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
610 +      mpfr_add_ui (x, x, 1, MPFR_RNDN);
611 +      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
612 +        ERROR1 (64);
613 +      mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
614 +      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
615 +        ERROR1 (65);
616 +      mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
617 +      mpfr_add_ui (x, x, 1, MPFR_RNDN);
618 +      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
619 +        ERROR1 (66);
620 +      mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
621 +      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
622 +        ERROR1 (67);
623 +      mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
624 +      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
625 +        ERROR1 (68);
626 +      mpfr_sub_ui (x, x, 1, MPFR_RNDN);
627 +      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
628 +        ERROR1 (69);
629  
630 -  /* Check negative value */
631 -  mpfr_set_si (x, -1, MPFR_RNDN);
632 -  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
633 -    ERROR2;
634 -  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
635 -    ERROR1;
636 +      /* Check negative op */
637 +      for (i = 1; i <= 4; i++)
638 +        {
639 +          int inv;
640 +
641 +          mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
642 +          mpfr_rint (y, x, (mpfr_rnd_t) r);
643 +          inv = MPFR_NOTZERO (y);
644 +          if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r) ^ inv)
645 +            ERROR1 (70);
646 +          if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
647 +            ERROR1 (71);
648 +        }
649 +    }
650  
651    mpfr_clear (x);
652 +  mpfr_clear (y);
653  #endif
654  }
655 -
656 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
657 --- mpfr-3.1.2-a/PATCHES        2013-10-09 13:34:21.000000000 +0000
658 +++ mpfr-3.1.2-b/PATCHES        2013-10-09 13:34:21.000000000 +0000
659 @@ -0,0 +1 @@
660 +clang-divby0
661 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
662 --- mpfr-3.1.2-a/VERSION        2013-09-26 10:52:52.000000000 +0000
663 +++ mpfr-3.1.2-b/VERSION        2013-10-09 13:34:21.000000000 +0000
664 @@ -1 +1 @@
665 -3.1.2-p2
666 +3.1.2-p3
667 diff -Naurd mpfr-3.1.2-a/src/mpfr-impl.h mpfr-3.1.2-b/src/mpfr-impl.h
668 --- mpfr-3.1.2-a/src/mpfr-impl.h        2013-03-13 15:37:36.000000000 +0000
669 +++ mpfr-3.1.2-b/src/mpfr-impl.h        2013-10-09 13:34:21.000000000 +0000
670 @@ -468,8 +468,16 @@
671  #define MPFR_LIMBS_PER_FLT ((IEEE_FLT_MANT_DIG-1)/GMP_NUMB_BITS+1)
672  
673  /* Visual C++ doesn't support +1.0/0.0, -1.0/0.0 and 0.0/0.0
674 -   at compile time. */
675 -#if defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)
676 +   at compile time.
677 +   Clang with -fsanitize=undefined is a bit similar due to a bug:
678 +     http://llvm.org/bugs/show_bug.cgi?id=17381
679 +   but even without its sanitizer, it may be better to use the
680 +   double_zero version until IEEE 754 division by zero is properly
681 +   supported:
682 +     http://llvm.org/bugs/show_bug.cgi?id=17000
683 +*/
684 +#if (defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)) || \
685 +    defined(__clang__)
686  static double double_zero = 0.0;
687  # define DBL_NAN (double_zero/double_zero)
688  # define DBL_POS_INF ((double) 1.0/double_zero)
689 @@ -501,6 +509,8 @@
690     (with Xcode 2.4.1, i.e. the latest one). */
691  #define LVALUE(x) (&(x) == &(x) || &(x) != &(x))
692  #define DOUBLE_ISINF(x) (LVALUE(x) && ((x) > DBL_MAX || (x) < -DBL_MAX))
693 +/* The DOUBLE_ISNAN(x) macro is also valid on long double x
694 +   (assuming that the compiler isn't too broken). */
695  #ifdef MPFR_NANISNAN
696  /* Avoid MIPSpro / IRIX64 / gcc -ffast-math (incorrect) optimizations.
697     The + must not be replaced by a ||. With gcc -ffast-math, NaN is
698 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
699 --- mpfr-3.1.2-a/src/mpfr.h     2013-09-26 10:52:52.000000000 +0000
700 +++ mpfr-3.1.2-b/src/mpfr.h     2013-10-09 13:34:21.000000000 +0000
701 @@ -27,7 +27,7 @@
702  #define MPFR_VERSION_MAJOR 3
703  #define MPFR_VERSION_MINOR 1
704  #define MPFR_VERSION_PATCHLEVEL 2
705 -#define MPFR_VERSION_STRING "3.1.2-p2"
706 +#define MPFR_VERSION_STRING "3.1.2-p3"
707  
708  /* Macros dealing with MPFR VERSION */
709  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
710 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
711 --- mpfr-3.1.2-a/src/version.c  2013-09-26 10:52:52.000000000 +0000
712 +++ mpfr-3.1.2-b/src/version.c  2013-10-09 13:34:21.000000000 +0000
713 @@ -25,5 +25,5 @@
714  const char *
715  mpfr_get_version (void)
716  {
717 -  return "3.1.2-p2";
718 +  return "3.1.2-p3";
719  }
720 diff -Naurd mpfr-3.1.2-a/tests/tget_flt.c mpfr-3.1.2-b/tests/tget_flt.c
721 --- mpfr-3.1.2-a/tests/tget_flt.c       2013-03-13 15:37:44.000000000 +0000
722 +++ mpfr-3.1.2-b/tests/tget_flt.c       2013-10-09 13:34:21.000000000 +0000
723 @@ -28,9 +28,17 @@
724  main (void)
725  {
726    mpfr_t x, y;
727 -  float f, g, infp;
728 +  float f, g;
729    int i;
730 +#if !defined(MPFR_ERRDIVZERO)
731 +  float infp;
732 +#endif
733 +
734 +  tests_start_mpfr ();
735  
736 +#if !defined(MPFR_ERRDIVZERO)
737 +  /* The definition of DBL_POS_INF involves a division by 0. This makes
738 +     "clang -O2 -fsanitize=undefined -fno-sanitize-recover" fail. */
739    infp = (float) DBL_POS_INF;
740    if (infp * 0.5 != infp)
741      {
742 @@ -38,8 +46,7 @@
743        fprintf (stderr, "(this is probably a compiler bug, please report)\n");
744        exit (1);
745      }
746 -
747 -  tests_start_mpfr ();
748 +#endif
749  
750    mpfr_init2 (x, 24);
751    mpfr_init2 (y, 24);
752 @@ -353,6 +360,7 @@
753        printf ("expected %.8e, got %.8e\n", g, f);
754        exit (1);
755      }
756 +#if !defined(MPFR_ERRDIVZERO)
757    f = mpfr_get_flt (x, MPFR_RNDN); /* first round to 2^128 (even rule),
758                                        thus we should get +Inf */
759    g = infp;
760 @@ -376,6 +384,7 @@
761        printf ("expected %.8e, got %.8e\n", g, f);
762        exit (1);
763      }
764 +#endif
765  
766    mpfr_clear (x);
767    mpfr_clear (y);
768 diff -Naurd mpfr-3.1.2-a/tests/tset_ld.c mpfr-3.1.2-b/tests/tset_ld.c
769 --- mpfr-3.1.2-a/tests/tset_ld.c        2013-03-13 15:37:44.000000000 +0000
770 +++ mpfr-3.1.2-b/tests/tset_ld.c        2013-10-09 13:34:21.000000000 +0000
771 @@ -47,8 +47,11 @@
772  static int
773  Isnan_ld (long double d)
774  {
775 -  double e = (double) d;
776 -  if (DOUBLE_ISNAN (e))
777 +  /* Do not convert d to double as this can give an overflow, which
778 +     may confuse compilers without IEEE 754 support (such as clang
779 +     -fsanitize=undefined), or trigger a trap if enabled.
780 +     The DOUBLE_ISNAN macro should work fine on long double. */
781 +  if (DOUBLE_ISNAN (d))
782      return 1;
783    LONGDOUBLE_NAN_ACTION (d, goto yes);
784    return 0;
785 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
786 --- mpfr-3.1.2-a/PATCHES        2013-11-15 00:51:49.211333830 +0000
787 +++ mpfr-3.1.2-b/PATCHES        2013-11-15 00:51:49.323334999 +0000
788 @@ -0,0 +1 @@
789 +printf-alt0
790 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
791 --- mpfr-3.1.2-a/VERSION        2013-11-15 00:51:49.211333830 +0000
792 +++ mpfr-3.1.2-b/VERSION        2013-11-15 00:51:49.323334999 +0000
793 @@ -1 +1 @@
794 -3.1.2-p3
795 +3.1.2-p4
796 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
797 --- mpfr-3.1.2-a/src/mpfr.h     2013-11-15 00:51:49.211333830 +0000
798 +++ mpfr-3.1.2-b/src/mpfr.h     2013-11-15 00:51:49.323334999 +0000
799 @@ -27,7 +27,7 @@
800  #define MPFR_VERSION_MAJOR 3
801  #define MPFR_VERSION_MINOR 1
802  #define MPFR_VERSION_PATCHLEVEL 2
803 -#define MPFR_VERSION_STRING "3.1.2-p3"
804 +#define MPFR_VERSION_STRING "3.1.2-p4"
805  
806  /* Macros dealing with MPFR VERSION */
807  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
808 diff -Naurd mpfr-3.1.2-a/src/vasprintf.c mpfr-3.1.2-b/src/vasprintf.c
809 --- mpfr-3.1.2-a/src/vasprintf.c        2013-03-13 15:37:37.000000000 +0000
810 +++ mpfr-3.1.2-b/src/vasprintf.c        2013-11-15 00:51:49.267334408 +0000
811 @@ -1040,7 +1040,7 @@
812  }
813  
814  /* Determine the different parts of the string representation of the regular
815 -   number P when SPEC.SPEC is 'e', 'E', 'g', or 'G'.
816 +   number P when spec.spec is 'e', 'E', 'g', or 'G'.
817     DEC_INFO contains the previously computed exponent and string or is NULL.
818  
819     return -1 if some field > INT_MAX */
820 @@ -1167,7 +1167,7 @@
821  }
822  
823  /* Determine the different parts of the string representation of the regular
824 -   number P when SPEC.SPEC is 'f', 'F', 'g', or 'G'.
825 +   number P when spec.spec is 'f', 'F', 'g', or 'G'.
826     DEC_INFO contains the previously computed exponent and string or is NULL.
827  
828     return -1 if some field of number_parts is greater than INT_MAX */
829 @@ -1559,7 +1559,7 @@
830              /* fractional part */
831              {
832                np->point = MPFR_DECIMAL_POINT;
833 -              np->fp_trailing_zeros = (spec.spec == 'g' && spec.spec == 'G') ?
834 +              np->fp_trailing_zeros = (spec.spec == 'g' || spec.spec == 'G') ?
835                  spec.prec - 1 : spec.prec;
836              }
837            else if (spec.alt)
838 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
839 --- mpfr-3.1.2-a/src/version.c  2013-11-15 00:51:49.211333830 +0000
840 +++ mpfr-3.1.2-b/src/version.c  2013-11-15 00:51:49.323334999 +0000
841 @@ -25,5 +25,5 @@
842  const char *
843  mpfr_get_version (void)
844  {
845 -  return "3.1.2-p3";
846 +  return "3.1.2-p4";
847  }
848 diff -Naurd mpfr-3.1.2-a/tests/tsprintf.c mpfr-3.1.2-b/tests/tsprintf.c
849 --- mpfr-3.1.2-a/tests/tsprintf.c       2013-03-13 15:37:44.000000000 +0000
850 +++ mpfr-3.1.2-b/tests/tsprintf.c       2013-11-15 00:51:49.267334408 +0000
851 @@ -456,10 +456,16 @@
852    check_sprintf ("1.999900  ", "%-#10.7RG", x);
853    check_sprintf ("1.9999    ", "%-10.7RG", x);
854    mpfr_set_ui (x, 1, MPFR_RNDN);
855 +  check_sprintf ("1.", "%#.1Rg", x);
856 +  check_sprintf ("1.   ", "%-#5.1Rg", x);
857 +  check_sprintf ("  1.0", "%#5.2Rg", x);
858    check_sprintf ("1.00000000000000000000000000000", "%#.30Rg", x);
859    check_sprintf ("1", "%.30Rg", x);
860    mpfr_set_ui (x, 0, MPFR_RNDN);
861 -  check_sprintf ("0.000000000000000000000000000000", "%#.30Rg", x);
862 +  check_sprintf ("0.", "%#.1Rg", x);
863 +  check_sprintf ("0.   ", "%-#5.1Rg", x);
864 +  check_sprintf ("  0.0", "%#5.2Rg", x);
865 +  check_sprintf ("0.00000000000000000000000000000", "%#.30Rg", x);
866    check_sprintf ("0", "%.30Rg", x);
867  
868    /* following tests with precision 53 bits */
869 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
870 --- mpfr-3.1.2-a/PATCHES        2013-12-01 11:07:49.575329762 +0000
871 +++ mpfr-3.1.2-b/PATCHES        2013-12-01 11:07:49.751331625 +0000
872 @@ -0,0 +1 @@
873 +custom_init_set
874 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
875 --- mpfr-3.1.2-a/VERSION        2013-12-01 11:07:49.571329714 +0000
876 +++ mpfr-3.1.2-b/VERSION        2013-12-01 11:07:49.747331585 +0000
877 @@ -1 +1 @@
878 -3.1.2-p4
879 +3.1.2-p5
880 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
881 --- mpfr-3.1.2-a/src/mpfr.h     2013-12-01 11:07:49.571329714 +0000
882 +++ mpfr-3.1.2-b/src/mpfr.h     2013-12-01 11:07:49.747331585 +0000
883 @@ -27,7 +27,7 @@
884  #define MPFR_VERSION_MAJOR 3
885  #define MPFR_VERSION_MINOR 1
886  #define MPFR_VERSION_PATCHLEVEL 2
887 -#define MPFR_VERSION_STRING "3.1.2-p4"
888 +#define MPFR_VERSION_STRING "3.1.2-p5"
889  
890  /* Macros dealing with MPFR VERSION */
891  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
892 @@ -861,7 +861,7 @@
893      _t = (mpfr_kind_t) _k;                                     \
894      _s = 1;                                                    \
895    } else {                                                     \
896 -    _t = (mpfr_kind_t) -k;                                     \
897 +    _t = (mpfr_kind_t) - _k;                                   \
898      _s = -1;                                                   \
899    }                                                            \
900    _e = _t == MPFR_REGULAR_KIND ? (e) :                         \
901 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
902 --- mpfr-3.1.2-a/src/version.c  2013-12-01 11:07:49.575329762 +0000
903 +++ mpfr-3.1.2-b/src/version.c  2013-12-01 11:07:49.747331585 +0000
904 @@ -25,5 +25,5 @@
905  const char *
906  mpfr_get_version (void)
907  {
908 -  return "3.1.2-p4";
909 +  return "3.1.2-p5";
910  }
911 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
912 --- mpfr-3.1.2-a/PATCHES        2014-04-15 21:56:49.609057464 +0000
913 +++ mpfr-3.1.2-b/PATCHES        2014-04-15 21:56:49.697059857 +0000
914 @@ -0,0 +1 @@
915 +li2-return
916 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
917 --- mpfr-3.1.2-a/VERSION        2014-04-15 21:56:49.609057464 +0000
918 +++ mpfr-3.1.2-b/VERSION        2014-04-15 21:56:49.697059857 +0000
919 @@ -1 +1 @@
920 -3.1.2-p5
921 +3.1.2-p6
922 diff -Naurd mpfr-3.1.2-a/src/li2.c mpfr-3.1.2-b/src/li2.c
923 --- mpfr-3.1.2-a/src/li2.c      2013-03-13 15:37:32.000000000 +0000
924 +++ mpfr-3.1.2-b/src/li2.c      2014-04-15 21:56:49.653058661 +0000
925 @@ -630,5 +630,5 @@
926        return mpfr_check_range (y, inexact, rnd_mode);
927      }
928  
929 -  MPFR_ASSERTN (0);             /* should never reach this point */
930 +  MPFR_RET_NEVER_GO_HERE ();
931  }
932 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
933 --- mpfr-3.1.2-a/src/mpfr.h     2014-04-15 21:56:49.609057464 +0000
934 +++ mpfr-3.1.2-b/src/mpfr.h     2014-04-15 21:56:49.697059857 +0000
935 @@ -27,7 +27,7 @@
936  #define MPFR_VERSION_MAJOR 3
937  #define MPFR_VERSION_MINOR 1
938  #define MPFR_VERSION_PATCHLEVEL 2
939 -#define MPFR_VERSION_STRING "3.1.2-p5"
940 +#define MPFR_VERSION_STRING "3.1.2-p6"
941  
942  /* Macros dealing with MPFR VERSION */
943  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
944 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
945 --- mpfr-3.1.2-a/src/version.c  2014-04-15 21:56:49.609057464 +0000
946 +++ mpfr-3.1.2-b/src/version.c  2014-04-15 21:56:49.697059857 +0000
947 @@ -25,5 +25,5 @@
948  const char *
949  mpfr_get_version (void)
950  {
951 -  return "3.1.2-p5";
952 +  return "3.1.2-p6";
953  }
954 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
955 --- mpfr-3.1.2-a/PATCHES        2014-04-15 22:04:57.090286262 +0000
956 +++ mpfr-3.1.2-b/PATCHES        2014-04-15 22:04:57.162288198 +0000
957 @@ -0,0 +1 @@
958 +exp3
959 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
960 --- mpfr-3.1.2-a/VERSION        2014-04-15 22:04:57.086286154 +0000
961 +++ mpfr-3.1.2-b/VERSION        2014-04-15 22:04:57.162288198 +0000
962 @@ -1 +1 @@
963 -3.1.2-p6
964 +3.1.2-p7
965 diff -Naurd mpfr-3.1.2-a/src/exp3.c mpfr-3.1.2-b/src/exp3.c
966 --- mpfr-3.1.2-a/src/exp3.c     2013-03-13 15:37:34.000000000 +0000
967 +++ mpfr-3.1.2-b/src/exp3.c     2014-04-15 22:04:57.126287230 +0000
968 @@ -283,7 +283,7 @@
969              }
970          }
971  
972 -      if (mpfr_can_round (shift_x > 0 ? t : tmp, realprec, MPFR_RNDD, MPFR_RNDZ,
973 +      if (mpfr_can_round (shift_x > 0 ? t : tmp, realprec, MPFR_RNDN, MPFR_RNDZ,
974                            MPFR_PREC(y) + (rnd_mode == MPFR_RNDN)))
975          {
976            inexact = mpfr_set (y, shift_x > 0 ? t : tmp, rnd_mode);
977 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
978 --- mpfr-3.1.2-a/src/mpfr.h     2014-04-15 22:04:57.086286154 +0000
979 +++ mpfr-3.1.2-b/src/mpfr.h     2014-04-15 22:04:57.162288198 +0000
980 @@ -27,7 +27,7 @@
981  #define MPFR_VERSION_MAJOR 3
982  #define MPFR_VERSION_MINOR 1
983  #define MPFR_VERSION_PATCHLEVEL 2
984 -#define MPFR_VERSION_STRING "3.1.2-p6"
985 +#define MPFR_VERSION_STRING "3.1.2-p7"
986  
987  /* Macros dealing with MPFR VERSION */
988  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
989 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
990 --- mpfr-3.1.2-a/src/version.c  2014-04-15 22:04:57.090286262 +0000
991 +++ mpfr-3.1.2-b/src/version.c  2014-04-15 22:04:57.162288198 +0000
992 @@ -25,5 +25,5 @@
993  const char *
994  mpfr_get_version (void)
995  {
996 -  return "3.1.2-p6";
997 +  return "3.1.2-p7";
998  }
999 diff -Naurd mpfr-3.1.2-a/tests/texp.c mpfr-3.1.2-b/tests/texp.c
1000 --- mpfr-3.1.2-a/tests/texp.c   2013-03-13 15:37:44.000000000 +0000
1001 +++ mpfr-3.1.2-b/tests/texp.c   2014-04-15 22:04:57.126287230 +0000
1002 @@ -150,6 +150,22 @@
1003        exit (1);
1004      }
1005  
1006 +  mpfr_set_prec (x, 118);
1007 +  mpfr_set_str_binary (x, "0.1110010100011101010000111110011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-86");
1008 +  mpfr_set_prec (y, 118);
1009 +  mpfr_exp_2 (y, x, MPFR_RNDU);
1010 +  mpfr_exp_3 (x, x, MPFR_RNDU);
1011 +  if (mpfr_cmp (x, y))
1012 +    {
1013 +      printf ("mpfr_exp_2 and mpfr_exp_3 differ for prec=118\n");
1014 +      printf ("mpfr_exp_2 gives ");
1015 +      mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
1016 +      printf ("\nmpfr_exp_3 gives ");
1017 +      mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
1018 +      printf ("\n");
1019 +      exit (1);
1020 +    }
1021 +
1022    mpfr_clear (x);
1023    mpfr_clear (y);
1024    return 0;
1025 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
1026 --- mpfr-3.1.2-a/PATCHES        2014-04-15 22:20:32.243481506 +0000
1027 +++ mpfr-3.1.2-b/PATCHES        2014-04-15 22:22:32.418722707 +0000
1028 @@ -0,0 +1 @@
1029 +gmp6-compat
1030 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
1031 --- mpfr-3.1.2-a/VERSION        2014-04-15 22:20:20.755171478 +0000
1032 +++ mpfr-3.1.2-b/VERSION        2014-04-15 22:21:45.225450147 +0000
1033 @@ -1 +1 @@
1034 -3.1.2-p7
1035 +3.1.2-p8
1036 diff -Naurd mpfr-3.1.2-a/configure mpfr-3.1.2-b/configure
1037 --- mpfr-3.1.2-a/configure      2013-03-13 15:38:20.000000000 +0000
1038 +++ mpfr-3.1.2-b/configure      2014-04-15 22:21:38.821277476 +0000
1039 @@ -14545,26 +14545,30 @@
1040  rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1041  fi
1042  
1043 -if test "$use_gmp_build" = yes ; then
1044 -  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for valid GMP_NUMB_BITS" >&5
1045 -$as_echo_n "checking for valid GMP_NUMB_BITS... " >&6; }
1046 -  if test "$cross_compiling" = yes; then :
1047 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency" >&5
1048 +$as_echo_n "checking for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency... " >&6; }
1049 +if test "$cross_compiling" = yes; then :
1050    { $as_echo "$as_me:${as_lineno-$LINENO}: result: can't test" >&5
1051  $as_echo "can't test" >&6; }
1052  else
1053    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1054  /* end confdefs.h.  */
1055  
1056 +#include <stdio.h>
1057  #include <limits.h>
1058  #include "gmp.h"
1059 -#include "gmp-impl.h"
1060  
1061  int
1062  main ()
1063  {
1064  
1065 -  return GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
1066 -         && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ? 0 : 1;
1067 +  if (GMP_NUMB_BITS == sizeof(mp_limb_t) * CHAR_BIT)
1068 +    return 0;
1069 +  fprintf (stderr, "GMP_NUMB_BITS     = %ld\n", (long) GMP_NUMB_BITS);
1070 +  fprintf (stderr, "sizeof(mp_limb_t) = %ld\n", (long) sizeof(mp_limb_t));
1071 +  fprintf (stderr, "sizeof(mp_limb_t) * CHAR_BIT = %ld != GMP_NUMB_BITS\n",
1072 +           (long) (sizeof(mp_limb_t) * CHAR_BIT));
1073 +  return 1;
1074  
1075    ;
1076    return 0;
1077 @@ -14577,14 +14581,14 @@
1078  
1079         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
1080  $as_echo "no" >&6; }
1081 -       as_fn_error $? "GMP_NUMB_BITS is incorrect.
1082 -You probably need to change some of the GMP or MPFR compile options." "$LINENO" 5
1083 +       as_fn_error $? "GMP_NUMB_BITS and sizeof(mp_limb_t) are not consistent.
1084 +You probably need to change some of the GMP or MPFR compile options.
1085 +See 'config.log' for details (search for GMP_NUMB_BITS)." "$LINENO" 5
1086  fi
1087  rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
1088    conftest.$ac_objext conftest.beam conftest.$ac_ext
1089  fi
1090  
1091 -fi
1092  
1093  
1094  if test "$dont_link_with_gmp" = yes ; then
1095 diff -Naurd mpfr-3.1.2-a/configure.ac mpfr-3.1.2-b/configure.ac
1096 --- mpfr-3.1.2-a/configure.ac   2013-03-13 15:37:46.000000000 +0000
1097 +++ mpfr-3.1.2-b/configure.ac   2013-03-13 15:37:46.000000000 +0000
1098 @@ -435,23 +435,29 @@
1099     ])
1100  fi
1101  
1102 -dnl Check for valid GMP_NUMB_BITS and BYTES_PER_MP_LIMB
1103 +dnl Check for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency.
1104 +dnl Problems may occur if gmp.h was generated with some ABI
1105 +dnl and is used with another ABI (or if nails are used).
1106  dnl This test doesn't need to link with libgmp (at least it shouldn't).
1107 -if test "$use_gmp_build" = yes ; then
1108 -  AC_MSG_CHECKING(for valid GMP_NUMB_BITS)
1109 -  AC_RUN_IFELSE([AC_LANG_PROGRAM([[
1110 +AC_MSG_CHECKING(for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency)
1111 +AC_RUN_IFELSE([AC_LANG_PROGRAM([[
1112 +#include <stdio.h>
1113  #include <limits.h>
1114  #include "gmp.h"
1115 -#include "gmp-impl.h"
1116  ]], [[
1117 -  return GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
1118 -         && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ? 0 : 1;
1119 +  if (GMP_NUMB_BITS == sizeof(mp_limb_t) * CHAR_BIT)
1120 +    return 0;
1121 +  fprintf (stderr, "GMP_NUMB_BITS     = %ld\n", (long) GMP_NUMB_BITS);
1122 +  fprintf (stderr, "sizeof(mp_limb_t) = %ld\n", (long) sizeof(mp_limb_t));
1123 +  fprintf (stderr, "sizeof(mp_limb_t) * CHAR_BIT = %ld != GMP_NUMB_BITS\n",
1124 +           (long) (sizeof(mp_limb_t) * CHAR_BIT));
1125 +  return 1;
1126  ]])], [AC_MSG_RESULT(yes)], [
1127         AC_MSG_RESULT(no)
1128 -       AC_MSG_ERROR([GMP_NUMB_BITS is incorrect.
1129 -You probably need to change some of the GMP or MPFR compile options.])],
1130 +       AC_MSG_ERROR([GMP_NUMB_BITS and sizeof(mp_limb_t) are not consistent.
1131 +You probably need to change some of the GMP or MPFR compile options.
1132 +See 'config.log' for details (search for GMP_NUMB_BITS).])],
1133         [AC_MSG_RESULT([can't test])])
1134 -fi
1135  
1136  
1137  dnl We really need to link using libtool. But it is impossible with the current
1138 diff -Naurd mpfr-3.1.2-a/src/init2.c mpfr-3.1.2-b/src/init2.c
1139 --- mpfr-3.1.2-a/src/init2.c    2013-03-13 15:37:32.000000000 +0000
1140 +++ mpfr-3.1.2-b/src/init2.c    2014-04-15 22:21:06.220398489 +0000
1141 @@ -30,11 +30,11 @@
1142  
1143    /* Check if we can represent the number of limbs
1144     * associated to the maximum of mpfr_prec_t*/
1145 -  MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/BYTES_PER_MP_LIMB) );
1146 +  MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/MPFR_BYTES_PER_MP_LIMB) );
1147  
1148 -  /* Check for correct GMP_NUMB_BITS and BYTES_PER_MP_LIMB */
1149 -  MPFR_ASSERTN( GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
1150 -                && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB );
1151 +  /* Check for correct GMP_NUMB_BITS and MPFR_BYTES_PER_MP_LIMB */
1152 +  MPFR_ASSERTN( GMP_NUMB_BITS == MPFR_BYTES_PER_MP_LIMB * CHAR_BIT
1153 +                && sizeof(mp_limb_t) == MPFR_BYTES_PER_MP_LIMB );
1154  
1155    MPFR_ASSERTN (mp_bits_per_limb == GMP_NUMB_BITS);
1156  
1157 diff -Naurd mpfr-3.1.2-a/src/mpfr-gmp.h mpfr-3.1.2-b/src/mpfr-gmp.h
1158 --- mpfr-3.1.2-a/src/mpfr-gmp.h 2013-03-13 15:37:32.000000000 +0000
1159 +++ mpfr-3.1.2-b/src/mpfr-gmp.h 2014-04-15 22:21:06.220398489 +0000
1160 @@ -72,7 +72,6 @@
1161  #endif
1162  
1163  /* Define some macros */
1164 -#define BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT)
1165  
1166  #define MP_LIMB_T_MAX (~(mp_limb_t)0)
1167  
1168 @@ -96,19 +95,19 @@
1169  #define SHRT_HIGHBIT       SHRT_MIN
1170  
1171  /* MP_LIMB macros */
1172 -#define MPN_ZERO(dst, n) memset((dst), 0, (n)*BYTES_PER_MP_LIMB)
1173 -#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
1174 -#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
1175 +#define MPN_ZERO(dst, n) memset((dst), 0, (n)*MPFR_BYTES_PER_MP_LIMB)
1176 +#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*MPFR_BYTES_PER_MP_LIMB)
1177 +#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*MPFR_BYTES_PER_MP_LIMB)
1178  #define MPN_COPY(dst,src,n) \
1179    do                                                                  \
1180      {                                                                 \
1181        if ((dst) != (src))                                             \
1182          {                                                             \
1183            MPFR_ASSERTD ((char *) (dst) >= (char *) (src) +            \
1184 -                                          (n) * BYTES_PER_MP_LIMB ||  \
1185 +                                     (n) * MPFR_BYTES_PER_MP_LIMB ||  \
1186                          (char *) (src) >= (char *) (dst) +            \
1187 -                                          (n) * BYTES_PER_MP_LIMB);   \
1188 -          memcpy ((dst), (src), (n) * BYTES_PER_MP_LIMB);             \
1189 +                                     (n) * MPFR_BYTES_PER_MP_LIMB);   \
1190 +          memcpy ((dst), (src), (n) * MPFR_BYTES_PER_MP_LIMB);        \
1191          }                                                             \
1192      }                                                                 \
1193    while (0)
1194 diff -Naurd mpfr-3.1.2-a/src/mpfr-impl.h mpfr-3.1.2-b/src/mpfr-impl.h
1195 --- mpfr-3.1.2-a/src/mpfr-impl.h        2013-10-09 13:34:21.000000000 +0000
1196 +++ mpfr-3.1.2-b/src/mpfr-impl.h        2014-04-15 22:21:06.220398489 +0000
1197 @@ -191,7 +191,7 @@
1198  # endif
1199  #endif
1200  
1201 -
1202 +#define MPFR_BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT)
1203  
1204  /******************************************************
1205   ******************** Check GMP ***********************
1206 @@ -930,7 +930,7 @@
1207  #define MPFR_SET_ALLOC_SIZE(x, n) \
1208   ( ((mp_size_t*) MPFR_MANT(x))[-1] = n)
1209  #define MPFR_MALLOC_SIZE(s) \
1210 -  ( sizeof(mpfr_size_limb_t) + BYTES_PER_MP_LIMB * ((size_t) s) )
1211 +  ( sizeof(mpfr_size_limb_t) + MPFR_BYTES_PER_MP_LIMB * ((size_t) s) )
1212  #define MPFR_SET_MANT_PTR(x,p) \
1213     (MPFR_MANT(x) = (mp_limb_t*) ((mpfr_size_limb_t*) p + 1))
1214  #define MPFR_GET_REAL_PTR(x) \
1215 @@ -964,7 +964,7 @@
1216  #endif
1217  
1218  #define MPFR_TMP_LIMBS_ALLOC(N) \
1219 -  ((mp_limb_t *) MPFR_TMP_ALLOC ((size_t) (N) * BYTES_PER_MP_LIMB))
1220 +  ((mp_limb_t *) MPFR_TMP_ALLOC ((size_t) (N) * MPFR_BYTES_PER_MP_LIMB))
1221  
1222  /* temporary allocate 1 limb at xp, and initialize mpfr variable x */
1223  /* The temporary var doesn't have any size field, but it doesn't matter
1224 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
1225 --- mpfr-3.1.2-a/src/mpfr.h     2014-04-15 22:20:20.755171478 +0000
1226 +++ mpfr-3.1.2-b/src/mpfr.h     2014-04-15 22:21:45.225450147 +0000
1227 @@ -27,7 +27,7 @@
1228  #define MPFR_VERSION_MAJOR 3
1229  #define MPFR_VERSION_MINOR 1
1230  #define MPFR_VERSION_PATCHLEVEL 2
1231 -#define MPFR_VERSION_STRING "3.1.2-p7"
1232 +#define MPFR_VERSION_STRING "3.1.2-p8"
1233  
1234  /* Macros dealing with MPFR VERSION */
1235  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
1236 diff -Naurd mpfr-3.1.2-a/src/mul.c mpfr-3.1.2-b/src/mul.c
1237 --- mpfr-3.1.2-a/src/mul.c      2013-03-13 15:37:37.000000000 +0000
1238 +++ mpfr-3.1.2-b/src/mul.c      2014-04-15 22:21:06.224398597 +0000
1239 @@ -106,7 +106,7 @@
1240    MPFR_ASSERTD(tn <= k);
1241  
1242    /* Check for no size_t overflow*/
1243 -  MPFR_ASSERTD((size_t) k <= ((size_t) -1) / BYTES_PER_MP_LIMB);
1244 +  MPFR_ASSERTD((size_t) k <= ((size_t) -1) / MPFR_BYTES_PER_MP_LIMB);
1245    MPFR_TMP_MARK(marker);
1246    tmp = MPFR_TMP_LIMBS_ALLOC (k);
1247  
1248 @@ -301,7 +301,7 @@
1249    MPFR_ASSERTD (tn <= k); /* tn <= k, thus no int overflow */
1250  
1251    /* Check for no size_t overflow*/
1252 -  MPFR_ASSERTD ((size_t) k <= ((size_t) -1) / BYTES_PER_MP_LIMB);
1253 +  MPFR_ASSERTD ((size_t) k <= ((size_t) -1) / MPFR_BYTES_PER_MP_LIMB);
1254    MPFR_TMP_MARK (marker);
1255    tmp = MPFR_TMP_LIMBS_ALLOC (k);
1256  
1257 diff -Naurd mpfr-3.1.2-a/src/stack_interface.c mpfr-3.1.2-b/src/stack_interface.c
1258 --- mpfr-3.1.2-a/src/stack_interface.c  2013-03-13 15:37:32.000000000 +0000
1259 +++ mpfr-3.1.2-b/src/stack_interface.c  2014-04-15 22:21:06.220398489 +0000
1260 @@ -26,7 +26,7 @@
1261  size_t
1262  mpfr_custom_get_size (mpfr_prec_t prec)
1263  {
1264 -  return MPFR_PREC2LIMBS (prec) * BYTES_PER_MP_LIMB;
1265 +  return MPFR_PREC2LIMBS (prec) * MPFR_BYTES_PER_MP_LIMB;
1266  }
1267  
1268  #undef mpfr_custom_init
1269 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
1270 --- mpfr-3.1.2-a/src/version.c  2014-04-15 22:20:20.755171478 +0000
1271 +++ mpfr-3.1.2-b/src/version.c  2014-04-15 22:21:45.225450147 +0000
1272 @@ -25,5 +25,5 @@
1273  const char *
1274  mpfr_get_version (void)
1275  {
1276 -  return "3.1.2-p7";
1277 +  return "3.1.2-p8";
1278  }
1279 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
1280 --- mpfr-3.1.2-a/PATCHES        2014-06-30 15:15:25.533266905 +0000
1281 +++ mpfr-3.1.2-b/PATCHES        2014-06-30 15:15:25.617269178 +0000
1282 @@ -0,0 +1 @@
1283 +div-overflow
1284 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
1285 --- mpfr-3.1.2-a/VERSION        2014-06-30 15:15:25.529266797 +0000
1286 +++ mpfr-3.1.2-b/VERSION        2014-06-30 15:15:25.617269178 +0000
1287 @@ -1 +1 @@
1288 -3.1.2-p8
1289 +3.1.2-p9
1290 diff -Naurd mpfr-3.1.2-a/src/div.c mpfr-3.1.2-b/src/div.c
1291 --- mpfr-3.1.2-a/src/div.c      2013-03-13 15:37:33.000000000 +0000
1292 +++ mpfr-3.1.2-b/src/div.c      2014-06-30 15:15:25.585268312 +0000
1293 @@ -750,7 +750,9 @@
1294   truncate_check_qh:
1295    if (qh)
1296      {
1297 -      qexp ++;
1298 +      if (MPFR_LIKELY (qexp < MPFR_EXP_MAX))
1299 +        qexp ++;
1300 +      /* else qexp is now incorrect, but one will still get an overflow */
1301        q0p[q0size - 1] = MPFR_LIMB_HIGHBIT;
1302      }
1303    goto truncate;
1304 @@ -765,7 +767,9 @@
1305    inex = 1; /* always here */
1306    if (mpn_add_1 (q0p, q0p, q0size, MPFR_LIMB_ONE << sh))
1307      {
1308 -      qexp ++;
1309 +      if (MPFR_LIKELY (qexp < MPFR_EXP_MAX))
1310 +        qexp ++;
1311 +      /* else qexp is now incorrect, but one will still get an overflow */
1312        q0p[q0size - 1] = MPFR_LIMB_HIGHBIT;
1313      }
1314  
1315 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
1316 --- mpfr-3.1.2-a/src/mpfr.h     2014-06-30 15:15:25.533266905 +0000
1317 +++ mpfr-3.1.2-b/src/mpfr.h     2014-06-30 15:15:25.613269070 +0000
1318 @@ -27,7 +27,7 @@
1319  #define MPFR_VERSION_MAJOR 3
1320  #define MPFR_VERSION_MINOR 1
1321  #define MPFR_VERSION_PATCHLEVEL 2
1322 -#define MPFR_VERSION_STRING "3.1.2-p8"
1323 +#define MPFR_VERSION_STRING "3.1.2-p9"
1324  
1325  /* Macros dealing with MPFR VERSION */
1326  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
1327 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
1328 --- mpfr-3.1.2-a/src/version.c  2014-06-30 15:15:25.533266905 +0000
1329 +++ mpfr-3.1.2-b/src/version.c  2014-06-30 15:15:25.613269070 +0000
1330 @@ -25,5 +25,5 @@
1331  const char *
1332  mpfr_get_version (void)
1333  {
1334 -  return "3.1.2-p8";
1335 +  return "3.1.2-p9";
1336  }
1337 diff -Naurd mpfr-3.1.2-a/tests/tdiv.c mpfr-3.1.2-b/tests/tdiv.c
1338 --- mpfr-3.1.2-a/tests/tdiv.c   2013-03-13 15:37:44.000000000 +0000
1339 +++ mpfr-3.1.2-b/tests/tdiv.c   2014-06-30 15:15:25.585268312 +0000
1340 @@ -1104,6 +1104,96 @@
1341  #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS)
1342  #include "tgeneric.c"
1343  
1344 +static void
1345 +test_extreme (void)
1346 +{
1347 +  mpfr_t x, y, z;
1348 +  mpfr_exp_t emin, emax;
1349 +  mpfr_prec_t p[4] = { 8, 32, 64, 256 };
1350 +  int xi, yi, zi, j, r;
1351 +  unsigned int flags, ex_flags;
1352 +
1353 +  emin = mpfr_get_emin ();
1354 +  emax = mpfr_get_emax ();
1355 +
1356 +  mpfr_set_emin (MPFR_EMIN_MIN);
1357 +  mpfr_set_emax (MPFR_EMAX_MAX);
1358 +
1359 +  for (xi = 0; xi < 4; xi++)
1360 +    {
1361 +      mpfr_init2 (x, p[xi]);
1362 +      mpfr_setmax (x, MPFR_EMAX_MAX);
1363 +      MPFR_ASSERTN (mpfr_check (x));
1364 +      for (yi = 0; yi < 4; yi++)
1365 +        {
1366 +          mpfr_init2 (y, p[yi]);
1367 +          mpfr_setmin (y, MPFR_EMIN_MIN);
1368 +          for (j = 0; j < 2; j++)
1369 +            {
1370 +              MPFR_ASSERTN (mpfr_check (y));
1371 +              for (zi = 0; zi < 4; zi++)
1372 +                {
1373 +                  mpfr_init2 (z, p[zi]);
1374 +                  RND_LOOP (r)
1375 +                    {
1376 +                      mpfr_clear_flags ();
1377 +                      mpfr_div (z, x, y, (mpfr_rnd_t) r);
1378 +                      flags = __gmpfr_flags;
1379 +                      MPFR_ASSERTN (mpfr_check (z));
1380 +                      ex_flags = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT;
1381 +                      if (flags != ex_flags)
1382 +                        {
1383 +                          printf ("Bad flags in test_extreme on z = a/b"
1384 +                                  " with %s and\n",
1385 +                                  mpfr_print_rnd_mode ((mpfr_rnd_t) r));
1386 +                          printf ("a = ");
1387 +                          mpfr_dump (x);
1388 +                          printf ("b = ");
1389 +                          mpfr_dump (y);
1390 +                          printf ("Expected flags:");
1391 +                          flags_out (ex_flags);
1392 +                          printf ("Got flags:     ");
1393 +                          flags_out (flags);
1394 +                          printf ("z = ");
1395 +                          mpfr_dump (z);
1396 +                          exit (1);
1397 +                        }
1398 +                      mpfr_clear_flags ();
1399 +                      mpfr_div (z, y, x, (mpfr_rnd_t) r);
1400 +                      flags = __gmpfr_flags;
1401 +                      MPFR_ASSERTN (mpfr_check (z));
1402 +                      ex_flags = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT;
1403 +                      if (flags != ex_flags)
1404 +                        {
1405 +                          printf ("Bad flags in test_extreme on z = a/b"
1406 +                                  " with %s and\n",
1407 +                                  mpfr_print_rnd_mode ((mpfr_rnd_t) r));
1408 +                          printf ("a = ");
1409 +                          mpfr_dump (y);
1410 +                          printf ("b = ");
1411 +                          mpfr_dump (x);
1412 +                          printf ("Expected flags:");
1413 +                          flags_out (ex_flags);
1414 +                          printf ("Got flags:     ");
1415 +                          flags_out (flags);
1416 +                          printf ("z = ");
1417 +                          mpfr_dump (z);
1418 +                          exit (1);
1419 +                        }
1420 +                    }
1421 +                  mpfr_clear (z);
1422 +                }  /* zi */
1423 +              mpfr_nextabove (y);
1424 +            }  /* j */
1425 +          mpfr_clear (y);
1426 +        }  /* yi */
1427 +      mpfr_clear (x);
1428 +    }  /* xi */
1429 +
1430 +  set_emin (emin);
1431 +  set_emax (emax);
1432 +}
1433 +
1434  int
1435  main (int argc, char *argv[])
1436  {
1437 @@ -1130,6 +1220,7 @@
1438    test_20070603 ();
1439    test_20070628 ();
1440    test_generic (2, 800, 50);
1441 +  test_extreme ();
1442  
1443    tests_end_mpfr ();
1444    return 0;
1445 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
1446 --- mpfr-3.1.2-a/PATCHES        2014-06-30 15:17:53.337268149 +0000
1447 +++ mpfr-3.1.2-b/PATCHES        2014-06-30 15:17:53.417270314 +0000
1448 @@ -0,0 +1 @@
1449 +vasprintf
1450 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
1451 --- mpfr-3.1.2-a/VERSION        2014-06-30 15:17:53.337268149 +0000
1452 +++ mpfr-3.1.2-b/VERSION        2014-06-30 15:17:53.413270206 +0000
1453 @@ -1 +1 @@
1454 -3.1.2-p9
1455 +3.1.2-p10
1456 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
1457 --- mpfr-3.1.2-a/src/mpfr.h     2014-06-30 15:17:53.337268149 +0000
1458 +++ mpfr-3.1.2-b/src/mpfr.h     2014-06-30 15:17:53.413270206 +0000
1459 @@ -27,7 +27,7 @@
1460  #define MPFR_VERSION_MAJOR 3
1461  #define MPFR_VERSION_MINOR 1
1462  #define MPFR_VERSION_PATCHLEVEL 2
1463 -#define MPFR_VERSION_STRING "3.1.2-p9"
1464 +#define MPFR_VERSION_STRING "3.1.2-p10"
1465  
1466  /* Macros dealing with MPFR VERSION */
1467  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
1468 diff -Naurd mpfr-3.1.2-a/src/vasprintf.c mpfr-3.1.2-b/src/vasprintf.c
1469 --- mpfr-3.1.2-a/src/vasprintf.c        2013-11-15 00:51:49.267334408 +0000
1470 +++ mpfr-3.1.2-b/src/vasprintf.c        2014-06-30 15:17:53.377269231 +0000
1471 @@ -884,14 +884,18 @@
1472             first digit, we want the exponent for radix two and the decimal
1473             point AFTER the first digit. */
1474          {
1475 -          MPFR_ASSERTN (exp > MPFR_EMIN_MIN /4); /* possible overflow */
1476 +          /* An integer overflow is normally not possible since MPFR_EXP_MIN
1477 +             is twice as large as MPFR_EMIN_MIN. */
1478 +          MPFR_ASSERTN (exp > (MPFR_EXP_MIN + 3) / 4);
1479            exp = (exp - 1) * 4;
1480          }
1481        else
1482          /* EXP is the exponent for decimal point BEFORE the first digit, we
1483             want the exponent for decimal point AFTER the first digit. */
1484          {
1485 -          MPFR_ASSERTN (exp > MPFR_EMIN_MIN); /* possible overflow */
1486 +          /* An integer overflow is normally not possible since MPFR_EXP_MIN
1487 +             is twice as large as MPFR_EMIN_MIN. */
1488 +          MPFR_ASSERTN (exp > MPFR_EXP_MIN);
1489            --exp;
1490          }
1491      }
1492 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
1493 --- mpfr-3.1.2-a/src/version.c  2014-06-30 15:17:53.337268149 +0000
1494 +++ mpfr-3.1.2-b/src/version.c  2014-06-30 15:17:53.413270206 +0000
1495 @@ -25,5 +25,5 @@
1496  const char *
1497  mpfr_get_version (void)
1498  {
1499 -  return "3.1.2-p9";
1500 +  return "3.1.2-p10";
1501  }
1502 diff -Naurd mpfr-3.1.2-a/tests/tsprintf.c mpfr-3.1.2-b/tests/tsprintf.c
1503 --- mpfr-3.1.2-a/tests/tsprintf.c       2013-11-15 00:51:49.267334408 +0000
1504 +++ mpfr-3.1.2-b/tests/tsprintf.c       2014-06-30 15:17:53.377269231 +0000
1505 @@ -1184,6 +1184,69 @@
1506    check_emax_aux (MPFR_EMAX_MAX);
1507  }
1508  
1509 +static void
1510 +check_emin_aux (mpfr_exp_t e)
1511 +{
1512 +  mpfr_t x;
1513 +  char *s1, s2[256];
1514 +  int i;
1515 +  mpfr_exp_t emin;
1516 +  mpz_t ee;
1517 +
1518 +  MPFR_ASSERTN (e >= LONG_MIN);
1519 +  emin = mpfr_get_emin ();
1520 +  set_emin (e);
1521 +
1522 +  mpfr_init2 (x, 16);
1523 +  mpz_init (ee);
1524 +
1525 +  mpfr_setmin (x, e);
1526 +  mpz_set_si (ee, e);
1527 +  mpz_sub_ui (ee, ee, 1);
1528 +
1529 +  i = mpfr_asprintf (&s1, "%Ra", x);
1530 +  MPFR_ASSERTN (i > 0);
1531 +
1532 +  gmp_snprintf (s2, 256, "0x1p%Zd", ee);
1533 +
1534 +  if (strcmp (s1, s2) != 0)
1535 +    {
1536 +      printf ("Error in check_emin_aux for emin = %ld\n", (long) e);
1537 +      printf ("Expected %s\n", s2);
1538 +      printf ("Got      %s\n", s1);
1539 +      exit (1);
1540 +    }
1541 +
1542 +  mpfr_free_str (s1);
1543 +
1544 +  i = mpfr_asprintf (&s1, "%Rb", x);
1545 +  MPFR_ASSERTN (i > 0);
1546 +
1547 +  gmp_snprintf (s2, 256, "1p%Zd", ee);
1548 +
1549 +  if (strcmp (s1, s2) != 0)
1550 +    {
1551 +      printf ("Error in check_emin_aux for emin = %ld\n", (long) e);
1552 +      printf ("Expected %s\n", s2);
1553 +      printf ("Got      %s\n", s1);
1554 +      exit (1);
1555 +    }
1556 +
1557 +  mpfr_free_str (s1);
1558 +
1559 +  mpfr_clear (x);
1560 +  mpz_clear (ee);
1561 +  set_emin (emin);
1562 +}
1563 +
1564 +static void
1565 +check_emin (void)
1566 +{
1567 +  check_emin_aux (-15);
1568 +  check_emin_aux (mpfr_get_emin ());
1569 +  check_emin_aux (MPFR_EMIN_MIN);
1570 +}
1571 +
1572  int
1573  main (int argc, char **argv)
1574  {
1575 @@ -1203,6 +1266,7 @@
1576    decimal ();
1577    mixed ();
1578    check_emax ();
1579 +  check_emin ();
1580  
1581  #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
1582    locale_da_DK ();
1583 diff -Naurd mpfr-3.1.2-a/PATCHES mpfr-3.1.2-b/PATCHES
1584 --- mpfr-3.1.2-a/PATCHES        2014-12-04 01:41:57.131789485 +0000
1585 +++ mpfr-3.1.2-b/PATCHES        2014-12-04 01:41:57.339791833 +0000
1586 @@ -0,0 +1 @@
1587 +strtofr
1588 diff -Naurd mpfr-3.1.2-a/VERSION mpfr-3.1.2-b/VERSION
1589 --- mpfr-3.1.2-a/VERSION        2014-12-04 01:41:57.127789443 +0000
1590 +++ mpfr-3.1.2-b/VERSION        2014-12-04 01:41:57.339791833 +0000
1591 @@ -1 +1 @@
1592 -3.1.2-p10
1593 +3.1.2-p11
1594 diff -Naurd mpfr-3.1.2-a/src/mpfr.h mpfr-3.1.2-b/src/mpfr.h
1595 --- mpfr-3.1.2-a/src/mpfr.h     2014-12-04 01:41:57.127789443 +0000
1596 +++ mpfr-3.1.2-b/src/mpfr.h     2014-12-04 01:41:57.335791790 +0000
1597 @@ -27,7 +27,7 @@
1598  #define MPFR_VERSION_MAJOR 3
1599  #define MPFR_VERSION_MINOR 1
1600  #define MPFR_VERSION_PATCHLEVEL 2
1601 -#define MPFR_VERSION_STRING "3.1.2-p10"
1602 +#define MPFR_VERSION_STRING "3.1.2-p11"
1603  
1604  /* Macros dealing with MPFR VERSION */
1605  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
1606 diff -Naurd mpfr-3.1.2-a/src/strtofr.c mpfr-3.1.2-b/src/strtofr.c
1607 --- mpfr-3.1.2-a/src/strtofr.c  2013-03-13 15:37:32.000000000 +0000
1608 +++ mpfr-3.1.2-b/src/strtofr.c  2014-12-04 01:41:57.287791246 +0000
1609 @@ -473,8 +473,10 @@
1610        /* prec bits corresponds to ysize limbs */
1611        ysize_bits = ysize * GMP_NUMB_BITS;
1612        /* and to ysize_bits >= prec > MPFR_PREC (x) bits */
1613 -      y = MPFR_TMP_LIMBS_ALLOC (2 * ysize + 1);
1614 -      y += ysize; /* y has (ysize+1) allocated limbs */
1615 +      /* we need to allocate one more limb to work around bug
1616 +         https://gmplib.org/list-archives/gmp-bugs/2013-December/003267.html */
1617 +      y = MPFR_TMP_LIMBS_ALLOC (2 * ysize + 2);
1618 +      y += ysize; /* y has (ysize+2) allocated limbs */
1619  
1620        /* pstr_size is the number of characters we read in pstr->mant
1621           to have at least ysize full limbs.
1622 diff -Naurd mpfr-3.1.2-a/src/version.c mpfr-3.1.2-b/src/version.c
1623 --- mpfr-3.1.2-a/src/version.c  2014-12-04 01:41:57.131789485 +0000
1624 +++ mpfr-3.1.2-b/src/version.c  2014-12-04 01:41:57.339791833 +0000
1625 @@ -25,5 +25,5 @@
1626  const char *
1627  mpfr_get_version (void)
1628  {
1629 -  return "3.1.2-p10";
1630 +  return "3.1.2-p11";
1631  }