ruby-changes:17607
From: usa <ko1@a...>
Date: Wed, 27 Oct 2010 18:54:57 +0900 (JST)
Subject: [ruby-changes:17607] Ruby:r29612 (trunk): * bignum.c (rb_big2long, rb_big2ulong): rb2ulong() returns VALUE, but
usa 2010-10-27 18:54:27 +0900 (Wed, 27 Oct 2010) New Revision: 29612 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29612 Log: * bignum.c (rb_big2long, rb_big2ulong): rb2ulong() returns VALUE, but its real range is ulong. So, if the size of VALUE is bigger than ulong, upper bits are always zero even if the actual value is negative. fixed #3490 Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29611) +++ ChangeLog (revision 29612) @@ -1,3 +1,11 @@ +Wed Oct 27 18:50:17 2010 NAKAMURA Usaku <usa@r...> + + * bignum.c (rb_big2long, rb_big2ulong): rb2ulong() returns VALUE, but + its real range is ulong. So, if the size of VALUE is bigger than + ulong, upper bits are always zero even if the actual value is + negative. + fixed #3490 + Wed Oct 27 18:27:17 2010 NAKAMURA Usaku <usa@r...> * test/ruby/test_io.rb (TestIO#pipe): should close write end of pipe Index: bignum.c =================================================================== --- bignum.c (revision 29611) +++ bignum.c (revision 29612) @@ -1176,7 +1176,7 @@ VALUE num = big2ulong(x, "unsigned long", TRUE); if (!RBIGNUM_SIGN(x)) { - if ((SIGNED_VALUE)num < 0) { + if ((long)num < 0) { rb_raise(rb_eRangeError, "bignum out of range of unsigned long"); } return (VALUE)(-(SIGNED_VALUE)num); @@ -1189,8 +1189,8 @@ { VALUE num = big2ulong(x, "long", TRUE); - if ((SIGNED_VALUE)num < 0 && - (RBIGNUM_SIGN(x) || (SIGNED_VALUE)num != LONG_MIN)) { + if ((long)num < 0 && + (RBIGNUM_SIGN(x) || (long)num != LONG_MIN)) { rb_raise(rb_eRangeError, "bignum too big to convert into `long'"); } if (!RBIGNUM_SIGN(x)) return -(SIGNED_VALUE)num; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/