Skip to content

Commit 5ba44d6

Browse files
committed
[Bug #22070] Fix segfault in Thread.each_caller_location
1 parent 33744d2 commit 5ba44d6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

test/ruby/test_backtrace.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ def test_each_backtrace_location
191191
assert_equal(cl.map(&:to_s), ary.map(&:to_s))
192192
end
193193

194+
def test_each_caller_location_single_cfunc_frame
195+
assert_normal_exit <<~'RUBY'
196+
tap { Thread.each_caller_location(1, 1) { |loc| loc.label } }
197+
RUBY
198+
199+
cl = nil; ary = []
200+
tap { cl = caller_locations(1, 1); Thread.each_caller_location(1, 1) { |x| ary << x } }
201+
assert_equal(cl.map(&:to_s), ary.map(&:to_s))
202+
end
203+
194204
def test_caller_locations_first_label
195205
def self.label
196206
caller_locations.first.label

vm_backtrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
751751
bt_backpatch_loc(backpatch_counter, loc, CFP_ISEQ(cfp), CFP_PC(cfp));
752752
RB_OBJ_WRITTEN(btobj, Qundef, CFP_ISEQ(cfp));
753753
if (do_yield) {
754-
bt_yield_loc(loc - backpatch_counter, backpatch_counter, btobj);
754+
bt_yield_loc(loc - backpatch_counter + 1, backpatch_counter, btobj);
755755
}
756756
break;
757757
}

0 commit comments

Comments
 (0)