summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-12 08:50:30 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-12 08:50:30 +0000
commit232257238acfaf3c34f3e6c4b2d6e1200fd217e8 (patch)
tree35b3725604669b7aca8d308e335770ec5e02d1d4 /numeric.c
parentfb44f02aa11674b5754f1053d40797ab6973b41d (diff)
* numeric (check_uint): set MSB for negative value.
* numeric (rb_num2uint): return value's type of rb_num2ulong is VALUE. * numeric (int_chr): variable i can't be negative. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/numeric.c b/numeric.c
index abc3b3efdd..9b01acfd10 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1791,7 +1791,8 @@ check_uint(VALUE num, VALUE sign)
if (RTEST(sign)) {
/* minus */
if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL)
- rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num);
+#define MSBMASK (1L << ((sizeof(long) * CHAR_BIT) - 1))
+ rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num|MSBMASK);
}
else {
/* plus */
@@ -1821,10 +1822,10 @@ rb_fix2int(VALUE val)
unsigned long
rb_num2uint(VALUE val)
{
- unsigned long num = rb_num2ulong(val);
+ VALUE num = rb_num2ulong(val);
check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
- return num;
+ return (unsigned long)num;
}
unsigned long
@@ -2091,13 +2092,11 @@ int_chr(int argc, VALUE *argv, VALUE num)
switch (argc) {
case 0:
- if (i < 0) {
- out_of_range:
- rb_raise(rb_eRangeError, "%d out of char range", i);
- }
if (0xff < i) {
enc = rb_default_internal_encoding();
- if (!enc) goto out_of_range;
+ if (!enc) {
+ rb_raise(rb_eRangeError, "%d out of char range", i);
+ }
goto decode;
}
c = (char)i;