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

mercurial at gmplib.org mercurial at gmplib.org
Mon May 18 15:41:02 UTC 2020


details:   /var/hg/gmp-6.2/rev/41cf58d0ec30
changeset: 18033:41cf58d0ec30
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon May 18 17:40:17 2020 +0200
description:
mpq/cmp.c: Avoid int overflow.

details:   /var/hg/gmp-6.2/rev/69a362c9c427
changeset: 18034:69a362c9c427
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon May 18 17:40:17 2020 +0200
description:
ChangeLog

diffstat:

 ChangeLog |  2 ++
 mpq/cmp.c |  3 ++-
 2 files changed, 4 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r 1cd5f139b2cb -r 69a362c9c427 ChangeLog
--- a/ChangeLog	Sun May 17 23:05:28 2020 +0200
+++ b/ChangeLog	Mon May 18 17:40:17 2020 +0200
@@ -1,6 +1,8 @@
 2020-05-17 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpz/cmp.c: Avoid overflow on int even for huge sizes.
+	* mpq/cmp.c: Likewise.
+
 	* mpn/generic/mul_fft.c (mpn_fft_mul_modF_K):
 	Fully handle carry propagation in basecase multiplication.
 
diff -r 1cd5f139b2cb -r 69a362c9c427 mpq/cmp.c
--- a/mpq/cmp.c	Sun May 17 23:05:28 2020 +0200
+++ b/mpq/cmp.c	Mon May 18 17:40:17 2020 +0200
@@ -70,8 +70,9 @@
     {
       int cmp;
 
+      /* Cannot use num1_sign - num2_size, may overflow an "int" */
       if (num1_sign != num2_size)
-	return num1_sign - num2_size;
+	return (num1_sign > num2_size) ? 1 : -1;
 
       cmp = mpn_cmp (PTR(NUM(op1)), PTR(num_op2), num1_size);
       return (num1_sign > 0 ? cmp : -cmp);



More information about the gmp-commit mailing list