summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--bignum.c34
-rw-r--r--version.h6
3 files changed, 30 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 36eca2c92d..732133161a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Jul 30 11:16:40 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * bignum.c (rb_big_aref): check for Bignum index range.
+ [ruby-dev:31271]
+
Sat Jul 28 09:35:41 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/digest/lib/digest.rb (Digest::self.const_missing): avoid
diff --git a/bignum.c b/bignum.c
index f5a47871d3..38717e4257 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2151,29 +2151,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);
}
diff --git a/version.h b/version.h
index 20cf32d4e7..54ac7f32fb 100644
--- a/version.h
+++ b/version.h
@@ -1,7 +1,7 @@
#define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2007-07-28"
+#define RUBY_RELEASE_DATE "2007-07-30"
#define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20070728
+#define RUBY_RELEASE_CODE 20070730
#define RUBY_PATCHLEVEL 5000
#define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 7
-#define RUBY_RELEASE_DAY 28
+#define RUBY_RELEASE_DAY 30
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];