[前][次][番号順一覧][スレッド一覧]

ruby-changes:18460

From: matz <ko1@a...>
Date: Fri, 7 Jan 2011 09:17:20 +0900 (JST)
Subject: [ruby-changes:18460] Ruby:r30483 (trunk): * bignum.c (bigmul1_karatsuba): avoid overflow that make assertion

matz	2011-01-07 09:17:06 +0900 (Fri, 07 Jan 2011)

  New Revision: 30483

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30483

  Log:
    * bignum.c (bigmul1_karatsuba): avoid overflow that make assertion
      fail in certain case.  this patch is contributed from Ray Chason
      <chasonr at gmail.com> in personal communication.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30482)
+++ ChangeLog	(revision 30483)
@@ -2,6 +2,12 @@
 
 	* string.c: parenthesize macro arguments.
 
+Thu Jan  6 22:42:02 2011  Yukihiro Matsumoto  <matz@r...>
+
+	* bignum.c (bigmul1_karatsuba): avoid overflow that make assertion
+	  fail in certain case.  this patch is contributed from Ray Chason
+	  <chasonr at gmail.com> in personal communication.
+
 Thu Jan  6 20:55:49 2011  NAKAMURA Usaku  <usa@r...>
 
 	* lib/mkmf.rb (create_makefile): ignore rest from first dot from
Index: bignum.c
===================================================================
--- bignum.c	(revision 30482)
+++ bignum.c	(revision 30483)
@@ -2157,15 +2157,15 @@
     t3 = bigmul0(xh, yh);
 
     i = xn + yn - n;
+    /* subtract t1 from t3 */
+    bigsub_core(BDIGITS(t3), big_real_len(t3), BDIGITS(t1), t1n, BDIGITS(t3), big_real_len(t3));
+
+    /* subtract t2 from t3; t3 is now the middle term of the product */
+    if (t2 != Qundef) bigsub_core(BDIGITS(t3), big_real_len(t3), BDIGITS(t2), t2n, BDIGITS(t3), big_real_len(t3));
+
     /* add t3 to middle bytes of the result (z1) */
     bigadd_core(zds + n, i, BDIGITS(t3), big_real_len(t3), zds + n, i);
 
-    /* subtract t1 from middle bytes of the result (z1) */
-    bigsub_core(zds + n, i, BDIGITS(t1), t1n, zds + n, i);
-
-    /* subtract t2 from middle bytes of the result (z1) */
-    if (t2 != Qundef) bigsub_core(zds + n, i, BDIGITS(t2), t2n, zds + n, i);
-
     return z;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]