summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-18 15:41:47 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-18 15:41:47 +0000
commit61a2d6baf35a0c61cc183659be040205a1e6e43b (patch)
treeae10bacfdb48b9b87cbd233a0fd6fffc2cd34ae5
parentfda0d27347e6eb86be2e71bcaf5a4b2fe1ea1ecc (diff)
Sat Jul 19 00:27:58 2008 NAKAMURA Usaku <[email protected]>
* 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@18129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--numeric.c25
2 files changed, 17 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 92f83b83c8..419c5282b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Jul 19 00:27:58 2008 NAKAMURA Usaku <[email protected]>
+
+ * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
+ about 64bit positive value.
Thu Jul 17 10:32:40 2008 NAKAMURA Usaku <[email protected]>
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
diff --git a/numeric.c b/numeric.c
index 28ac6ca8a1..4f181035ae 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1600,20 +1600,21 @@ check_int(num)
}
static void
-check_uint(num)
+check_uint(num, sign)
unsigned long num;
+ VALUE sign;
{
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);
+ 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);
}
}
@@ -1643,7 +1644,7 @@ rb_num2uint(val)
{
unsigned long num = rb_num2ulong(val);
- check_uint(num);
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
@@ -1658,7 +1659,7 @@ rb_fix2uint(val)
}
num = FIX2ULONG(val);
- check_uint(num);
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
#else