1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fixed infinite loop at error in printing cause [Bug #17033]

This commit is contained in:
Nobuyoshi Nakada 2020-07-15 18:46:07 +09:00
parent 79d06483a8
commit 579645d9f8
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
Notes: git 2020-07-15 23:04:04 +09:00
2 changed files with 25 additions and 1 deletions

View file

@ -362,6 +362,7 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo)
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)
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;

View file

@ -814,6 +814,26 @@ end.join
}
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