diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 02:48:36 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 02:48:36 +0000 |
commit | 215f80a9a021d40f63de1b811d81f48fd5424d42 (patch) | |
tree | a7a220f6d2a3ab40c5f921f690d89263e847a27a | |
parent | c64c48ff32ae3e170d77d8eb37ad3f1788e3b440 (diff) |
* bignum.c (rb_big_aref): check for Bignum index range.
[ruby-dev:31271]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@13208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 34 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 28 insertions, 13 deletions
@@ -1,3 +1,8 @@ +Wed Aug 22 11:47:11 2007 Nobuyoshi Nakada <[email protected]> + + * bignum.c (rb_big_aref): check for Bignum index range. + [ruby-dev:31271] + Wed Aug 22 11:41:44 2007 Nobuyoshi Nakada <[email protected]> * dln.c (conv_to_posix_path): removed. @@ -2049,29 +2049,39 @@ rb_big_aref(x, y) VALUE x, y; { BDIGIT *xds; - int shift; - long s1, s2; + BDIGIT_DBL num; + unsigned long shift; + long i, s1, s2; if (TYPE(y) == T_BIGNUM) { - if (!RBIGNUM(y)->sign || RBIGNUM(x)->sign) + if (!RBIGNUM(y)->sign) return INT2FIX(0); - return INT2FIX(1); + if (RBIGNUM(bigtrunc(y))->len > SIZEOF_LONG/SIZEOF_BDIGITS) { + out_of_range: + return RBIGNUM(x)->sign ? INT2FIX(0) : INT2FIX(1); + } + shift = big2ulong(y, "long", Qfalse); + } + else { + i = NUM2LONG(y); + if (i < 0) return INT2FIX(0); + shift = (VALUE)i; } - shift = NUM2INT(y); - if (shift < 0) return INT2FIX(0); s1 = shift/BITSPERDIG; s2 = shift%BITSPERDIG; + if (s1 >= RBIGNUM(x)->len) goto out_of_range; if (!RBIGNUM(x)->sign) { - if (s1 >= RBIGNUM(x)->len) return INT2FIX(1); - x = rb_big_clone(x); - get2comp(x); + xds = BDIGITS(x); + i = 0; num = 1; + while (num += ~xds[i], ++i <= s1) { + num = BIGDN(num); + } } else { - if (s1 >= RBIGNUM(x)->len) return INT2FIX(0); + num = BDIGITS(x)[s1]; } - xds = BDIGITS(x); - if (xds[s1] & (1<<s2)) + if (num & ((BDIGIT_DBL)1<<s2)) return INT2FIX(1); return INT2FIX(0); } @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2007-08-22" #define RUBY_VERSION_CODE 186 #define RUBY_RELEASE_CODE 20070822 -#define RUBY_PATCHLEVEL 80 +#define RUBY_PATCHLEVEL 81 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 |