summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--numeric.c25
-rw-r--r--version.h2
3 files changed, 26 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index e011673..39653dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon Aug 4 12:25:08 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
+ about 64bit positive value.
+Mon Aug 4 12:25:08 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
+ fixed [ruby-dev:33683]
+
Mon Aug 4 12:11:29 2008 Tanaka Akira <akr@fsij.org>
* gc.c (Init_GC): fix syntax error.
diff --git a/numeric.c b/numeric.c
index 98d5f96..21a4f2a 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1597,11 +1597,21 @@ check_int(num)
}
static void
-check_uint(num)
+check_uint(num, sign)
unsigned long num;
+ VALUE sign;
{
- if (num > UINT_MAX) {
- rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
+ static const unsigned long mask = ~(unsigned long)UINT_MAX;
+
+ if (RTEST(sign)) {
+ /* minus */
+ if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL)
+ rb_raise(rb_eRangeError, "integer %ld too small to convert to `unsigned int'", num);
+ }
+ else {
+ /* plus */
+ if ((num & mask) != 0)
+ rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
}
}
@@ -1631,9 +1641,7 @@ rb_num2uint(val)
{
unsigned long num = rb_num2ulong(val);
- if (RTEST(rb_funcall(INT2FIX(0), '<', 1, val))) {
- check_uint(num);
- }
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
@@ -1647,9 +1655,8 @@ rb_fix2uint(val)
return rb_num2uint(val);
}
num = FIX2ULONG(val);
- if (FIX2LONG(val) > 0) {
- check_uint(num);
- }
+
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
#else
diff --git a/version.h b/version.h
index 00fc1a5..0af3b51 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-08-04"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20080804
-#define RUBY_PATCHLEVEL 280
+#define RUBY_PATCHLEVEL 281
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8