Skip to content

Commit 0b0b794

Browse files
authored
Simplify close_lexical_var (#726)
Its implementation was borderline wrong: calling it with is_arg=TRUE segfaults because it looks up the var ref index in the wrong array. Fortunately, there is only one caller and it only passes FALSE.
1 parent aca0a09 commit 0b0b794

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

quickjs.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -14612,15 +14612,14 @@ static void close_var_refs(JSRuntime *rt, JSStackFrame *sf)
1461214612
}
1461314613
}
1461414614

14615-
static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int idx, int is_arg)
14615+
static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int var_idx)
1461614616
{
1461714617
struct list_head *el, *el1;
1461814618
JSVarRef *var_ref;
14619-
int var_idx = idx;
1462014619

1462114620
list_for_each_safe(el, el1, &sf->var_ref_list) {
1462214621
var_ref = list_entry(el, JSVarRef, header.link);
14623-
if (var_idx == var_ref->var_idx && var_ref->is_arg == is_arg) {
14622+
if (var_idx == var_ref->var_idx && !var_ref->is_arg) {
1462414623
var_ref->value = js_dup(sf->var_buf[var_idx]);
1462514624
var_ref->pvalue = &var_ref->value;
1462614625
list_del(&var_ref->header.link);
@@ -15873,7 +15872,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
1587315872
int idx;
1587415873
idx = get_u16(pc);
1587515874
pc += 2;
15876-
close_lexical_var(ctx, sf, idx, FALSE);
15875+
close_lexical_var(ctx, sf, idx);
1587715876
}
1587815877
BREAK;
1587915878

0 commit comments

Comments
 (0)