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

mercurial at gmplib.org mercurial at gmplib.org
Wed Feb 12 19:51:11 UTC 2020


details:   /var/hg/gmp/rev/8d5d3b0f0a79
changeset: 18044:8d5d3b0f0a79
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Feb 12 20:14:44 2020 +0100
description:
mpz/cmp{,abs}.c: Avoid any overflow.

details:   /var/hg/gmp/rev/55cb6670515d
changeset: 18045:55cb6670515d
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Feb 12 20:48:32 2020 +0100
description:
NEWS

details:   /var/hg/gmp/rev/c44538397385
changeset: 18046:c44538397385
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Feb 12 20:48:35 2020 +0100
description:
ChangeLog

diffstat:

 ChangeLog    |  5 +++++
 NEWS         |  9 +++++++++
 mpz/cmp.c    |  8 ++++----
 mpz/cmpabs.c |  8 ++++----
 4 files changed, 22 insertions(+), 8 deletions(-)

diffs (77 lines):

diff -r f5601c2a8b11 -r c44538397385 ChangeLog
--- a/ChangeLog	Sun Feb 09 16:16:19 2020 +0100
+++ b/ChangeLog	Wed Feb 12 20:48:35 2020 +0100
@@ -1,3 +1,8 @@
+2020-02-12 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/cmp.c: Avoid overflow on int even for huge sizes.
+	* mpz/cmpabs.c: Likewise.
+
 2020-02-09 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpn/generic/sqrmod_bnm1.c (mpn_bc_sqrmod_bnp1):
diff -r f5601c2a8b11 -r c44538397385 NEWS
--- a/NEWS	Sun Feb 09 16:16:19 2020 +0100
+++ b/NEWS	Wed Feb 12 20:48:35 2020 +0100
@@ -3,6 +3,15 @@
 Verbatim copying and distribution of this entire article is permitted in any
 medium, provided this notice is preserved.
 
+Changes between GMP version 6.2.* and *.*.*
+
+  BUGS FIXED
+  * A possible overflow of type int is avoided for mpz_cmp on huge operands.
+
+  SPEEDUPS
+  * New special code for base = 2 in mpz_powm reduces the average time
+    for the functions that test primality.
+
 Changes between GMP version 6.1.* and 6.2.0
 
   BUGS FIXED
diff -r f5601c2a8b11 -r c44538397385 mpz/cmp.c
--- a/mpz/cmp.c	Sun Feb 09 16:16:19 2020 +0100
+++ b/mpz/cmp.c	Wed Feb 12 20:48:35 2020 +0100
@@ -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);
diff -r f5601c2a8b11 -r c44538397385 mpz/cmpabs.c
--- a/mpz/cmpabs.c	Sun Feb 09 16:16:19 2020 +0100
+++ b/mpz/cmpabs.c	Wed Feb 12 20:48:35 2020 +0100
@@ -36,15 +36,15 @@
 int
 mpz_cmpabs (mpz_srcptr u, mpz_srcptr v) __GMP_NOTHROW
 {
-  mp_size_t  usize, vsize, dsize;
+  mp_size_t  usize, vsize;
   mp_srcptr  up, vp;
   int        cmp;
 
   usize = ABSIZ (u);
   vsize = ABSIZ (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;
 
   up = PTR(u);
   vp = PTR(v);


More information about the gmp-commit mailing list