diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-17 00:14:16 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-17 00:14:16 +0900 |
| commit | 5140e27b5a970d717138fe0b15b20e345f7ea5f6 (patch) | |
| tree | 004ccdf96f3220088aa11b6b05f4c727da5f9adf | |
| parent | 777d460fb8cdf6108d9b9cb260adf9665789bc23 (diff) | |
| parent | 9dcce29749db652ca22a3ffb28a56c1c0f04572d (diff) | |
| download | mruby-5140e27b5a970d717138fe0b15b20e345f7ea5f6.tar.gz mruby-5140e27b5a970d717138fe0b15b20e345f7ea5f6.zip | |
Merge pull request #1872 from ksss/numeric-mul
fix bug when `0 * other object`
| -rw-r--r-- | src/numeric.c | 2 | ||||
| -rw-r--r-- | test/t/integer.rb | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c index e2af14b97..066c5e154 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -690,10 +690,10 @@ mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y) mrb_int a; a = mrb_fixnum(x); - if (a == 0) return x; if (mrb_fixnum_p(y)) { mrb_int b, c; + if (a == 0) return x; b = mrb_fixnum(y); if (FIT_SQRT_INT(a) && FIT_SQRT_INT(b)) return mrb_fixnum_value(a*b); diff --git a/test/t/integer.rb b/test/t/integer.rb index 2bffce5a9..486224c85 100644 --- a/test/t/integer.rb +++ b/test/t/integer.rb @@ -31,6 +31,9 @@ assert('Integer#*', '15.2.8.3.3') do assert_equal 1, a assert_equal 1.0, b + + assert_raise(TypeError){ 0*nil } + assert_raise(TypeError){ 1*nil } end assert('Integer#/', '15.2.8.3.4') do |
