diff options
| author | ksss <[email protected]> | 2014-03-16 23:08:31 +0900 |
|---|---|---|
| committer | ksss <[email protected]> | 2014-03-16 23:08:31 +0900 |
| commit | 9dcce29749db652ca22a3ffb28a56c1c0f04572d (patch) | |
| tree | 607aaec9b40b78113960f71bc07a48a49b0657e4 | |
| parent | 18bebd3acdea1124b3d192ffc171eb6807d391cf (diff) | |
| download | mruby-9dcce29749db652ca22a3ffb28a56c1c0f04572d.tar.gz mruby-9dcce29749db652ca22a3ffb28a56c1c0f04572d.zip | |
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 38a05ae92..af293b1fb 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 |
