[Gmp-commit] /var/hg/gmp: mpn/sparc64/dive_1.c: Avoid undefined behavior: << 64.

mercurial at gmplib.org mercurial at gmplib.org
Sun Nov 17 17:34:45 UTC 2019


details:   /var/hg/gmp/rev/d296f15b0eec
changeset: 17966:d296f15b0eec
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 17 18:34:30 2019 +0100
description:
mpn/sparc64/dive_1.c: Avoid undefined behavior: << 64.

diffstat:

 mpn/sparc64/dive_1.c |  18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diffs (40 lines):

diff -r 8e6f40b1f0a9 -r d296f15b0eec mpn/sparc64/dive_1.c
--- a/mpn/sparc64/dive_1.c	Sun Nov 17 09:21:36 2019 +0100
+++ b/mpn/sparc64/dive_1.c	Sun Nov 17 18:34:30 2019 +0100
@@ -4,7 +4,7 @@
    CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
    FUTURE GNU MP RELEASES.
 
-Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
+Copyright 2000, 2001, 2003, 2019 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -87,17 +87,21 @@
     {
       count_trailing_zeros (rshift, divisor);
       divisor >>= rshift;
+      lshift = 64 - rshift;
+
+      lshift_mask = MP_LIMB_T_MAX;
     }
   else
-    rshift = 0;
+    {
+      rshift = 0;
+
+      /* rshift==0 means no shift, so must mask out other part in this case */
+      lshift = 0;
+      lshift_mask = 0;
+    }
 
   binvert_limb (inverse, divisor);
 
-  lshift = 64 - rshift;
-
-  /* lshift==64 means no shift, so must mask out other part in this case */
-  lshift_mask = (rshift == 0 ? 0 : MP_LIMB_T_MAX);
-
   c = 0;
   divisor_h = HIGH32 (divisor);
 


More information about the gmp-commit mailing list