diff libtommath/bn_mp_div_2d.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 8bba51a55704
children f52919ffd3b1
line wrap: on
line diff
--- a/libtommath/bn_mp_div_2d.c	Tue Jan 23 23:27:40 2018 +0800
+++ b/libtommath/bn_mp_div_2d.c	Sat Feb 17 19:29:51 2018 +0800
@@ -20,8 +20,6 @@
 {
   mp_digit D, r, rr;
   int     x, res;
-  mp_int  t;
-
 
   /* if the shift count is <= 0 then we do no work */
   if (b <= 0) {
@@ -32,24 +30,19 @@
     return res;
   }
 
-  if ((res = mp_init (&t)) != MP_OKAY) {
+  /* copy */
+  if ((res = mp_copy (a, c)) != MP_OKAY) {
     return res;
   }
+  /* 'a' should not be used after here - it might be the same as d */
 
   /* get the remainder */
   if (d != NULL) {
-    if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) {
-      mp_clear (&t);
+    if ((res = mp_mod_2d (a, b, d)) != MP_OKAY) {
       return res;
     }
   }
 
-  /* copy */
-  if ((res = mp_copy (a, c)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-
   /* shift by as many digits in the bit count */
   if (b >= (int)DIGIT_BIT) {
     mp_rshd (c, b / DIGIT_BIT);
@@ -84,14 +77,10 @@
     }
   }
   mp_clamp (c);
-  if (d != NULL) {
-    mp_exch (&t, d);
-  }
-  mp_clear (&t);
   return MP_OKAY;
 }
 #endif
 
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */