[Gmp-commit] /var/hg/gmp-6.2: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Sun Sep 20 22:36:00 UTC 2020


details:   /var/hg/gmp-6.2/rev/ffa11d30ea7d
changeset: 18077:ffa11d30ea7d
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Mon Sep 21 00:35:33 2020 +0200
description:
Detect and report overflow.

details:   /var/hg/gmp-6.2/rev/0ec09ebea62d
changeset: 18078:0ec09ebea62d
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Mon Sep 21 00:35:51 2020 +0200
description:
ChangeLog

diffstat:

 ChangeLog      |  13 +++++++++++++
 mpz/n_pow_ui.c |  24 +++++++++++++++++++++---
 2 files changed, 34 insertions(+), 3 deletions(-)

diffs (82 lines):

diff -r 2a99844c8d54 -r 0ec09ebea62d ChangeLog
--- a/ChangeLog	Thu Sep 17 10:05:52 2020 +0200
+++ b/ChangeLog	Mon Sep 21 00:35:51 2020 +0200
@@ -1,3 +1,16 @@
+2020-09-21  Torbjörn Granlund  <tg at gmplib.org>
+
+	* mpz/n_pow_ui.c: Detect and report overflow.
+
+2020-07-04  Torbjörn Granlund  <tg at gmplib.org>
+
+	* mpn/arm64/bdiv_q_1.asm: Use LEA_HI/LEA_LO
+	* mpn/arm64/invert_limb.asm: Likewise.
+
+	* mpn/arm64/arm64-defs.m4: New file.
+	* mpn/arm64/darwin.m4: New file.
+	* configure.ac: Use arm64/arm64-defs.m4 and arm64/darwin.m4.
+
 2020-06-20  Torbjörn Granlund  <tg at gmplib.org>
 
 	* longlong.h (add_sssaaaa arm32/arm64): Generalise allowed operands
diff -r 2a99844c8d54 -r 0ec09ebea62d mpz/n_pow_ui.c
--- a/mpz/n_pow_ui.c	Thu Sep 17 10:05:52 2020 +0200
+++ b/mpz/n_pow_ui.c	Mon Sep 21 00:35:51 2020 +0200
@@ -4,7 +4,7 @@
    CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
    FUTURE GNU MP RELEASES.
 
-Copyright 2001, 2002, 2005, 2012, 2015 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2005, 2012, 2015, 2020 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -32,6 +32,8 @@
 GNU Lesser General Public License along with the GNU MP Library.  If not,
 see https://www.gnu.org/licenses/.  */
 
+#include <stdlib.h>
+#include <stdio.h>
 #include "gmp-impl.h"
 #include "longlong.h"
 
@@ -170,6 +172,7 @@
 #else
   mp_limb_t      b_twolimbs[2];
 #endif
+  mp_limb_t ovfl;
   TMP_DECL;
 
   TRACE (printf ("mpz_n_pow_ui rp=0x%lX bp=0x%lX bsize=%ld e=%lu (0x%lX)\n",
@@ -213,7 +216,14 @@
   /* Strip low zero bits from b. */
   count_trailing_zeros (btwos, blimb);
   blimb >>= btwos;
-  rtwos_bits = e * btwos;
+
+  umul_ppmm (ovfl, rtwos_bits, e, btwos);
+  if (ovfl)
+    {
+      fprintf (stderr, "gmp: overflow in mpz type\n");
+      abort ();
+    }
+
   rtwos_limbs += rtwos_bits / GMP_NUMB_BITS;
   rtwos_bits %= GMP_NUMB_BITS;
   TRACE (printf ("trailing zero btwos=%d rtwos_limbs=%ld rtwos_bits=%lu\n",
@@ -368,7 +378,15 @@
 
   ASSERT (blimb != 0);
   count_leading_zeros (cnt, blimb);
-  ralloc = (bsize*GMP_NUMB_BITS - cnt + GMP_NAIL_BITS) * e / GMP_NUMB_BITS + 5;
+
+  umul_ppmm (ovfl, ralloc, (bsize*GMP_NUMB_BITS - cnt + GMP_NAIL_BITS), e);
+  if (ovfl)
+    {
+      fprintf (stderr, "gmp: overflow in mpz type\n");
+      abort ();
+    }
+  ralloc = ralloc / GMP_NUMB_BITS + 5;
+
   TRACE (printf ("ralloc %ld, from bsize=%ld blimb=0x%lX cnt=%d\n",
 		 ralloc, bsize, blimb, cnt));
   rp = MPZ_NEWALLOC (r, ralloc + rtwos_limbs);



More information about the gmp-commit mailing list