summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-18 15:29:17 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-18 15:29:17 +0000
commit404d0ad40fd654a6429d896fef3601f934d11786 (patch)
tree6a64094030005f42e64716d4108db1e0ce4831fa
parent305b347ae5fac1e4d64f80d62adc69911603c700 (diff)
* 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/trunk@18126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--numeric.c29
2 files changed, 20 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index d97f9a2418..d21bdda97c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jul 19 00:27:58 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
+ about 64bit positive value.
+
Fri Jul 18 23:23:37 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (EVENTSINK_Invoke): avoid cfp consistency
diff --git a/numeric.c b/numeric.c
index 3e1c467a12..2b4d958a68 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1585,25 +1585,26 @@ check_int(SIGNED_VALUE num)
}
static void
-check_uint(VALUE num)
+check_uint(VALUE num, VALUE sign)
{
static const VALUE mask = ~(VALUE)UINT_MAX;
- static const VALUE msb =
-#if SIZEOF_LONG == SIZEOF_VALUE
- ~LONG_MAX;
-#elif SIZEOF_LONG_LONG == SIZEOF_VALUE
- ~LLONG_MAX;
-#endif
const char *s;
- if ((num & mask) != 0 &&
- ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL)) {
- if ((num & msb) == 0)
+ if (RTEST(sign)) {
+ /* minus */
+ if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL)
+ s = "small";
+ else
+ return;
+ }
+ else {
+ /* plus */
+ if ((num & mask) != 0)
s = "big";
else
- s = "small";
- rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `unsigned int'", num, s);
+ return;
}
+ rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `unsigned int'", num, s);
}
long
@@ -1629,7 +1630,7 @@ rb_num2uint(VALUE val)
{
unsigned long num = rb_num2ulong(val);
- check_uint(num);
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
@@ -1643,7 +1644,7 @@ rb_fix2uint(VALUE val)
}
num = FIX2ULONG(val);
- check_uint(num);
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
#else