[Gmp-commit] /var/hg/gmp: Don't assume >= 2 limbs in mod argument.

mercurial at gmplib.org mercurial at gmplib.org
Wed Dec 5 17:34:11 CET 2012


details:   /var/hg/gmp/rev/406e8bebd91d
changeset: 15159:406e8bebd91d
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Wed Dec 05 17:34:09 2012 +0100
description:
Don't assume >= 2 limbs in mod argument.

diffstat:

 ChangeLog     |  2 ++
 mpz/powm_ui.c |  5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r bb71fe32ad47 -r 406e8bebd91d ChangeLog
--- a/ChangeLog	Wed Dec 05 13:22:43 2012 +0100
+++ b/ChangeLog	Wed Dec 05 17:34:09 2012 +0100
@@ -1,5 +1,7 @@
 2012-12-05  Torbjorn Granlund  <tege at gmplib.org>
 
+	* mpz/powm_ui.c: Don't assume >= 2 limbs in mod argument.
+
 	* tests/tests.h (TESTS_REPS): Handle float GMP_CHECK_REPFACTOR.
 
 	* longlong.h: Refine cpp test for vax.
diff -r bb71fe32ad47 -r 406e8bebd91d mpz/powm_ui.c
--- a/mpz/powm_ui.c	Wed Dec 05 13:22:43 2012 +0100
+++ b/mpz/powm_ui.c	Wed Dec 05 17:34:09 2012 +0100
@@ -105,7 +105,7 @@
       mp_size_t xn, tn, mn, bn;
       int m_zero_cnt;
       int c;
-      mp_limb_t e;
+      mp_limb_t e, m2;
       gmp_pi1_t dinv;
       TMP_DECL;
 
@@ -136,7 +136,8 @@
 	  mp = new_mp;
 	}
 
-      invert_pi1 (dinv, mp[mn - 1], mp[mn - 2]);
+      m2 = mn == 1 ? 0 : mp[mn - 2];
+      invert_pi1 (dinv, mp[mn - 1], m2);
 
       bn = ABSIZ(b);
       bp = PTR(b);


More information about the gmp-commit mailing list