summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-17 01:32:58 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-17 01:32:58 +0000
commitb4e38121045c55192ca8274391a3c13acd4da34c (patch)
tree7dfe34d5d16a24298e0f20691d3a558a55943ef4
parent0c694317dd2e036f6bca362d6b53bee43069d868 (diff)
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
fixed [ruby-dev:33683] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@18100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--numeric.c24
2 files changed, 19 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index f409f6723e..92f83b83c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jul 17 10:32:40 2008 NAKAMURA Usaku <[email protected]>
+
+ * numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
+ fixed [ruby-dev:33683]
+
Tue Jul 15 23:00:17 2008 NAKAMURA Usaku <[email protected]>
* {bcc32,win32}/Makefile.sub (ruby_version): follow changes in
diff --git a/numeric.c b/numeric.c
index 57e61d5ee0..28ac6ca8a1 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1603,8 +1603,17 @@ static void
check_uint(num)
unsigned long num;
{
- 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;
+ static const unsigned long msb = ~LONG_MAX;
+ const char *s;
+
+ if ((num & mask) != 0 &&
+ ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL)) {
+ if ((num & msb) == 0)
+ s = "big";
+ else
+ s = "small";
+ rb_raise(rb_eRangeError, "integer %ld too %s to convert to `unsigned int'", num, s);
}
}
@@ -1634,10 +1643,7 @@ rb_num2uint(val)
{
unsigned long num = rb_num2ulong(val);
- if (RTEST(rb_funcall(val, '<', 1, INT2FIX(0))))
- check_int(num);
- else
- check_uint(num);
+ check_uint(num);
return num;
}
@@ -1651,10 +1657,8 @@ rb_fix2uint(val)
return rb_num2uint(val);
}
num = FIX2ULONG(val);
- if (RTEST(rb_funcall(val, '<', 1, INT2FIX(0))))
- check_int(num);
- else
- check_uint(num);
+
+ check_uint(num);
return num;
}
#else