[Bug #19774] Fix segfault at return in END

This commit is contained in:
Nobuyoshi Nakada 2023-07-19 01:27:45 +09:00
parent ac7d34026a
commit fe4d906f5f
Notes: git 2023-07-18 18:40:35 +00:00
2 changed files with 11 additions and 1 deletions

View File

@ -461,7 +461,12 @@ exiting_split(VALUE errinfo, volatile int *exitcode, volatile int *sigstatus)
if (NIL_P(errinfo)) return 0;
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
if (THROW_DATA_P(errinfo)) {
int throw_state = ((const struct vm_throw_data *)errinfo)->throw_state;
ex = throw_state & VM_THROW_STATE_MASK;
result |= EXITING_WITH_STATUS;
}
else if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
ex = sysexit_status(errinfo);
result |= EXITING_WITH_STATUS;
}

View File

@ -1370,6 +1370,7 @@ eom
nil&defined?0--begin e=no_method_error(); return; 0;end
return puts('ignored') #=> ignored
BEGIN {return}
END {return if false}
end;
.split(/\n/).map {|s|[(line+=1), *s.split(/#=> /, 2)]}
failed = proc do |n, s|
@ -1407,6 +1408,10 @@ eom
assert_in_out_err(['-e', 'class TestSyntax; proc{ return }.call; end'], "", [], /^-e:1:.*unexpected return \(LocalJumpError\)/)
end
def test_return_in_END
assert_normal_exit('END {return}')
end
def test_syntax_error_in_rescue
bug12613 = '[ruby-core:76531] [Bug #12613]'
assert_syntax_error("#{<<-"begin;"}\n#{<<-"end;"}", /Invalid retry/, bug12613)