summaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-07 13:24:55 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-07 13:24:55 +0000
commitd771eb69027f2827c2f3f3edee5dd2c1a9678bc8 (patch)
treecf7ac9993a3155bb992e063238c34c144973c093 /numeric.c
parent4ba19c715d75866e152ad0e7226d5c6fa1b1e592 (diff)
downloadruby-d771eb69027f2827c2f3f3edee5dd2c1a9678bc8.tar.gz
ruby-d771eb69027f2827c2f3f3edee5dd2c1a9678bc8.tar.xz
ruby-d771eb69027f2827c2f3f3edee5dd2c1a9678bc8.zip
* numeric.c (bit_coerce): float should not be a valid operand of
bitwise operations. [ruby-dev:34583] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/numeric.c b/numeric.c
index 775f392e5..999c970a9 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2636,9 +2636,12 @@ fix_rev(VALUE num)
}
static VALUE
-fix_coerce(VALUE x)
+bit_coerce(VALUE x)
{
while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
+ if (TYPE(x) == T_FLOAT) {
+ rb_raise(rb_eTypeError, "can't convert Float into Integer");
+ }
x = rb_to_int(x);
}
return x;
@@ -2656,7 +2659,7 @@ fix_and(VALUE x, VALUE y)
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (!FIXNUM_P(y = bit_coerce(y))) {
return rb_big_and(y, x);
}
val = FIX2LONG(x) & FIX2LONG(y);
@@ -2675,7 +2678,7 @@ fix_or(VALUE x, VALUE y)
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (!FIXNUM_P(y = bit_coerce(y))) {
return rb_big_or(y, x);
}
val = FIX2LONG(x) | FIX2LONG(y);
@@ -2694,7 +2697,7 @@ fix_xor(VALUE x, VALUE y)
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (!FIXNUM_P(y = bit_coerce(y))) {
return rb_big_xor(y, x);
}
val = FIX2LONG(x) ^ FIX2LONG(y);
@@ -2791,7 +2794,8 @@ fix_aref(VALUE fix, VALUE idx)
long val = FIX2LONG(fix);
long i;
- if (!FIXNUM_P(idx = fix_coerce(idx))) {
+ idx = rb_to_int(idx);
+ if (!FIXNUM_P(idx)) {
idx = rb_big_norm(idx);
if (!FIXNUM_P(idx)) {
if (!RBIGNUM_SIGN(idx) || val >= 0)