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

mercurial at gmplib.org mercurial at gmplib.org
Mon May 18 07:36:32 UTC 2020


details:   /var/hg/gmp-6.2/rev/fc94a3eb41fe
changeset: 18029:fc94a3eb41fe
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 17 22:25:31 2020 +0200
description:
mpn/generic/mul_fft.c (mpn_fft_mul_modF_K): Fully handle carry propagation in basecase multiplication

details:   /var/hg/gmp-6.2/rev/a89113c6c0b0
changeset: 18030:a89113c6c0b0
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 17 22:26:23 2020 +0200
description:
mpz/cmp.c: Avoid any overflow.

details:   /var/hg/gmp-6.2/rev/d23bb47b2d04
changeset: 18031:d23bb47b2d04
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 17 23:04:15 2020 +0200
description:
ChangeLog

details:   /var/hg/gmp-6.2/rev/1cd5f139b2cb
changeset: 18032:1cd5f139b2cb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 17 23:05:28 2020 +0200
description:
NEWS

diffstat:

 ChangeLog             |   6 ++++++
 NEWS                  |   5 +++++
 mpn/generic/mul_fft.c |   9 ++++++---
 mpz/cmp.c             |  12 ++++++------
 4 files changed, 23 insertions(+), 9 deletions(-)

diffs (89 lines):

diff -r e1a7c5f2168f -r 1cd5f139b2cb ChangeLog
--- a/ChangeLog	Sun May 17 01:06:15 2020 +0200
+++ b/ChangeLog	Sun May 17 23:05:28 2020 +0200
@@ -1,3 +1,9 @@
+2020-05-17 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/cmp.c: Avoid overflow on int even for huge sizes.
+	* mpn/generic/mul_fft.c (mpn_fft_mul_modF_K):
+	Fully handle carry propagation in basecase multiplication.
+
 2020-05-16  Torbjörn Granlund  <tg at gmplib.org>
 
 	* mpn/generic/hgcd2.c (tabp): Combine several undefined tabp
diff -r e1a7c5f2168f -r 1cd5f139b2cb NEWS
--- a/NEWS	Sun May 17 01:06:15 2020 +0200
+++ b/NEWS	Sun May 17 23:05:28 2020 +0200
@@ -3,6 +3,11 @@
 Verbatim copying and distribution of this entire article is permitted in any
 medium, provided this notice is preserved.
 
+Changes between GMP version 6.2.0 and 6.2.1
+
+  BUGS FIXED
+  * A possible overflow of type int is avoided for mpz_cmp on huge operands.
+
 Changes between GMP version 6.1.* and 6.2.0
 
   BUGS FIXED
diff -r e1a7c5f2168f -r 1cd5f139b2cb mpn/generic/mul_fft.c
--- a/mpn/generic/mul_fft.c	Sun May 17 01:06:15 2020 +0200
+++ b/mpn/generic/mul_fft.c	Sun May 17 23:05:28 2020 +0200
@@ -6,7 +6,7 @@
    SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 1998-2010, 2012, 2013, 2018 Free Software Foundation, Inc.
+Copyright 1998-2010, 2012, 2013, 2018, 2020 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -553,9 +553,12 @@
 	    cc += mpn_add_n (tpn, tpn, a, n) + a[n];
 	  if (cc != 0)
 	    {
-	      /* FIXME: use MPN_INCR_U here, since carry is not expected.  */
 	      cc = mpn_add_1 (tp, tp, n2, cc);
-	      ASSERT (cc == 0);
+	      /* If mpn_add_1 give a carry (cc != 0),
+		 the result (tp) is at most GMP_NUMB_MAX - 1,
+		 so the following addition can't overflow.
+	      */
+	      tp[0] += cc;
 	    }
 	  a[n] = mpn_sub_n (a, tp, tpn, n) && mpn_add_1 (a, a, n, CNST_LIMB(1));
 	}
diff -r e1a7c5f2168f -r 1cd5f139b2cb mpz/cmp.c
--- a/mpz/cmp.c	Sun May 17 01:06:15 2020 +0200
+++ b/mpz/cmp.c	Sun May 17 23:05:28 2020 +0200
@@ -1,8 +1,8 @@
 /* mpz_cmp(u,v) -- Compare U, V.  Return positive, zero, or negative
    based on if U > V, U == V, or U < V.
 
-Copyright 1991, 1993, 1994, 1996, 2001, 2002, 2011 Free Software Foundation,
-Inc.
+Copyright 1991, 1993, 1994, 1996, 2001, 2002, 2011, 2020 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -35,15 +35,15 @@
 int
 mpz_cmp (mpz_srcptr u, mpz_srcptr v) __GMP_NOTHROW
 {
-  mp_size_t  usize, vsize, dsize, asize;
+  mp_size_t  usize, vsize, asize;
   mp_srcptr  up, vp;
   int        cmp;
 
   usize = SIZ(u);
   vsize = SIZ(v);
-  dsize = usize - vsize;
-  if (dsize != 0)
-    return dsize;
+  /* Cannot use usize - vsize, may overflow an "int" */
+  if (usize != vsize)
+    return (usize > vsize) ? 1 : -1;
 
   asize = ABS (usize);
   up = PTR(u);



More information about the gmp-commit mailing list