summaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-04 08:52:51 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-04 08:52:51 +0000
commitbe8215fb7f51566abde6da5cca1f6fea82590364 (patch)
tree86f087873a41fd8c3a228278c1fc83643883aefb /numeric.c
parentb41a9ae5e8dbdc5b6e67d77ed68a1b3ed363fb67 (diff)
downloadruby-be8215fb7f51566abde6da5cca1f6fea82590364.tar.gz
ruby-be8215fb7f51566abde6da5cca1f6fea82590364.tar.xz
ruby-be8215fb7f51566abde6da5cca1f6fea82590364.zip
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): proper check.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@17870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/numeric.c b/numeric.c
index 07b5ae6e4..83f1d3c43 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1585,10 +1585,10 @@ check_int(SIGNED_VALUE num)
}
static void
-check_uint(VALUE num, int sign)
+check_uint(VALUE num)
{
if (num > UINT_MAX) {
- rb_raise(rb_eRangeError, "integer %"PRIuVALUE " too %s to convert to `unsigned int'", num, sign ? "small" : "big");
+ rb_raise(rb_eRangeError, "integer %"PRIuVALUE " too big to convert to `unsigned int'", num);
}
}
@@ -1615,7 +1615,10 @@ rb_num2uint(VALUE val)
{
unsigned long num = rb_num2ulong(val);
- check_uint(num, RTEST(rb_funcall(val, '<', 1, INT2FIX(0))));
+ if (RTEST(rb_funcall(val, '<', 1, INT2FIX(0))))
+ check_int(num);
+ else
+ check_uint(num);
return num;
}
@@ -1628,7 +1631,10 @@ rb_fix2uint(VALUE val)
return rb_num2uint(val);
}
num = FIX2ULONG(val);
- check_uint(num, RTEST(rb_funcall(val, '<', 1, INT2FIX(0))));
+ if (RTEST(rb_funcall(val, '<', 1, INT2FIX(0))))
+ check_int(num);
+ else
+ check_uint(num);
return num;
}
#else