summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-04 04:31:06 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-04 04:31:06 +0000
commit519f06ed80093df52922eb0e48d5264037f4916d (patch)
tree58381f20f713af92194cbadefadec945315dc122
parent3056186947891523de7a4f86b8bebea8f422559a (diff)
merge revision(s) 18100,18129:
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check. fixed [ruby-dev:33683] * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check about 64bit positive value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@18329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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 e011673041..39653dc5fd 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 98d5f96001..21a4f2af4c 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 00fc1a5978..0af3b51413 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