[Gmp-commit] /var/hg/gmp: mpq/cmp.c: Avoid int overflow.

mercurial at gmplib.org mercurial at gmplib.org
Sun May 17 21:00:54 UTC 2020


details:   /var/hg/gmp/rev/df0effd0a69e
changeset: 18076:df0effd0a69e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 17 22:55:12 2020 +0200
description:
mpq/cmp.c: Avoid int overflow.

diffstat:

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

diffs (14 lines):

diff -r 52b67a736f7c -r df0effd0a69e mpq/cmp.c
--- a/mpq/cmp.c	Sun May 17 01:06:02 2020 +0200
+++ b/mpq/cmp.c	Sun May 17 22:55:12 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