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

ruby-changes:29952

From: akr <ko1@a...>
Date: Tue, 16 Jul 2013 19:08:32 +0900 (JST)
Subject: [ruby-changes:29952] akr:r42004 (trunk): * bignum.c (big_shift3): Big shift width is not a problem for right

akr	2013-07-16 19:08:25 +0900 (Tue, 16 Jul 2013)

  New Revision: 42004

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

  Log:
    * bignum.c (big_shift3): Big shift width is not a problem for right
      shift.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42003)
+++ ChangeLog	(revision 42004)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul 16 19:05:12 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (big_shift3): Big shift width is not a problem for right
+	  shift.
+
 Tue Jul 16 18:50:08 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* array.c (rb_ary_count): [DOC] fix typo.  Array#count uses ==, not
@@ -7,7 +12,7 @@ Tue Jul 16 18:35:48 2013  Tanaka Akira https://github.com/ruby/ruby/blob/trunk/ChangeLog#L12
 
 	* bignum.c (bary_mul_karatsuba): Avoid duplicate calculation when
 	  squaring.
-	  ((bary_mul_toom3_branch): Ditto.
+	  (bary_mul_toom3_branch): Ditto.
 
 Tue Jul 16 17:43:22 2013  Koichi Sasada  <ko1@a...>
 
Index: bignum.c
===================================================================
--- bignum.c	(revision 42003)
+++ bignum.c	(revision 42004)
@@ -3263,14 +3263,12 @@ big_shift3(VALUE x, int lshift_p, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L3263
     VALUE z;
     long xn;
 
-    if (LONG_MAX < shift_numdigits) {
-        rb_raise(rb_eArgError, "too big number");
-    }
-
-    s1 = shift_numdigits;
-    s2 = shift_numbits;
-
     if (lshift_p) {
+        if (LONG_MAX < shift_numdigits) {
+            rb_raise(rb_eArgError, "too big number");
+        }
+        s1 = shift_numdigits;
+        s2 = shift_numbits;
         xn = RBIGNUM_LEN(x);
         z = bignew(xn+s1+1, RBIGNUM_SIGN(x));
         zds = BDIGITS(z);
@@ -3281,13 +3279,15 @@ big_shift3(VALUE x, int lshift_p, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L3279
     else {
         long zn;
         BDIGIT hibitsx;
-        if (s1 >= RBIGNUM_LEN(x)) {
+        if (LONG_MAX < shift_numdigits || (size_t)RBIGNUM_LEN(x) <= shift_numdigits) {
             if (RBIGNUM_POSITIVE_P(x) ||
                 bary_zero_p(BDIGITS(x), RBIGNUM_LEN(x)))
                 return INT2FIX(0);
             else
                 return INT2FIX(-1);
         }
+        s1 = shift_numdigits;
+        s2 = shift_numbits;
         hibitsx = abs2twocomp(&x, &xn);
         xds = BDIGITS(x);
         if (xn <= s1) {

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

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