Skip to content

Commit f58f7f2

Browse files
committed
Fix bug of uninitialized variable, missed EoCFP, return values
1 parent 81f3591 commit f58f7f2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

vm.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,37 @@ static const VALUE *
9999
VM_EP_RUBY_LEP(const rb_execution_context_t *ec, const rb_control_frame_t *current_cfp)
100100
{
101101
const VALUE *ep = current_cfp->ep;
102-
const rb_control_frame_t *cfp, *checkpoint_cfp = current_cfp;
102+
const rb_control_frame_t * const eocfp = RUBY_VM_END_CONTROL_FRAME(ec); /* end of control frame pointer */
103+
const rb_control_frame_t *cfp = NULL, *checkpoint_cfp = current_cfp;
103104

104105
while (!VM_ENV_LOCAL_P(ep) || VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_CFUNC)) {
105106
while (!VM_ENV_LOCAL_P(ep)) {
106107
ep = VM_ENV_PREV_EP(ep);
107108
}
108-
while (VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_CFUNC)) {
109+
while (VM_ENV_FLAGS(ep, VM_FRAME_FLAG_CFRAME) != 0) {
109110
if (!cfp) {
110111
cfp = rb_vm_search_cf_from_ep(ec, checkpoint_cfp, ep);
112+
VM_ASSERT(cfp, "rb_vm_search_cf_from_ep should return a valid cfp for the ep");
113+
VM_ASSERT(cfp->ep == ep);
114+
}
115+
if (!cfp) {
116+
return NULL;
117+
}
118+
VM_ASSERT(cfp->ep);
119+
VM_ASSERT(cfp->ep == ep);
120+
121+
if (VM_FRAME_FINISHED_P(cfp)) {
122+
rb_bug("CFUNC frame should not FINISHED");
111123
}
112124
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
125+
if (cfp >= eocfp) {
126+
return NULL;
127+
}
128+
VM_ASSERT(cfp, "CFUNC should have a valid previous control frame");
113129
ep = cfp->ep;
130+
if (!ep) {
131+
return NULL;
132+
}
114133
}
115134
checkpoint_cfp = cfp;
116135
cfp = NULL;

0 commit comments

Comments
 (0)