summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--insns.def2
-rw-r--r--test/ruby/test_optimization.rb11
3 files changed, 18 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 187e10f4f9..d1d199dd59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Dec 11 17:59:05 2015 Eric Wong <e@80x24.org>
+
+ * insns.def (opt_case_dispatch): avoid converting Infinity
+ * test/ruby/test_optimization.rb (test_opt_case_dispatch_inf): new
+ [ruby-dev:49423] [Bug #11804]'
+
Fri Dec 11 16:48:57 2015 Eric Wong <e@80x24.org>
* hash.c (rb_num_hash_start): avoid pathological behavior
diff --git a/insns.def b/insns.def
index 3c185bd084..df65aa8efd 100644
--- a/insns.def
+++ b/insns.def
@@ -1262,7 +1262,7 @@ opt_case_dispatch
switch(TYPE(key)) {
case T_FLOAT: {
double ival;
- if (modf(RFLOAT_VALUE(key), &ival) == 0.0) {
+ if (modf(RFLOAT_VALUE(key), &ival) == 0.0 && !isinf(ival)) {
key = FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
}
}
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 1c50044f7f..3573d1267f 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -362,4 +362,15 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_redefine_method(k, '===', "assert_equal(#{v.inspect} === 0, 0)")
end
end
+
+ def test_opt_case_dispatch_inf
+ inf = 1.0/0.0
+ result = case inf
+ when 1 then 1
+ when 0 then 0
+ else
+ inf.to_i rescue nil
+ end
+ assert_nil result, '[ruby-dev:49423] [Bug #11804]'
+ end
end