ruby-changes:62253
From: Nobuyoshi <ko1@a...>
Date: Wed, 15 Jul 2020 23:04:01 +0900 (JST)
Subject: [ruby-changes:62253] 579645d9f8 (master): Fixed infinite loop at error in printing cause [Bug #17033]
https://git.ruby-lang.org/ruby.git/commit/?id=579645d9f8 From 579645d9f870fa4116dcd3200bbbb6e2c0b7f400 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 15 Jul 2020 18:46:07 +0900 Subject: Fixed infinite loop at error in printing cause [Bug #17033] diff --git a/eval_error.c b/eval_error.c index e8a7243..1e6579c 100644 --- a/eval_error.c +++ b/eval_error.c @@ -362,6 +362,7 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L362 volatile uint8_t raised_flag = ec->raised_flag; volatile VALUE errat = Qundef; volatile VALUE emesg = Qundef; + volatile bool written = false; if (NIL_P(errinfo)) return; @@ -376,7 +377,10 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L377 emesg = rb_get_message(errinfo); } - rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qfalse); + if (!written) { + written = true; + rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qfalse); + } EC_POP_TAG(); ec->errinfo = errinfo; diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 9529fc8..4decddc 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -814,6 +814,26 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L814 } end + def test_cause_exception_in_cause_message + assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}") do |outs, errs, status| + begin; + exc = Class.new(StandardError) do + def initialize(obj, cnt) + super(obj) + @errcnt = cnt + end + def to_s + return super if @errcnt <= 0 + @errcnt -= 1 + raise "xxx" + end + end.new("ok", 10) + raise "[Bug #17033]", cause: exc + end; + assert_equal(1, errs.count {|m| m.include?("[Bug #17033]")}, proc {errs.pretty_inspect}) + end + end + def test_anonymous_message assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/) end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/