mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7a5d45fc3c
commit
5cf605b1d2
2 changed files with 11 additions and 3 deletions
|
@ -1,3 +1,11 @@
|
|||
Wed Oct 27 18:50:17 2010 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_io.rb (TestIO#pipe): should close write end of pipe
|
||||
|
|
6
bignum.c
6
bignum.c
|
@ -1176,7 +1176,7 @@ rb_big2ulong(VALUE x)
|
|||
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 @@ rb_big2long(VALUE x)
|
|||
{
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue