Skip to content

Commit a9b84ad

Browse files
dummyxk0kubun
authored andcommitted
string.c: guard tmp in rb_str_format_m (rubyGH-16280)
[Bug #21931] Keep tmp alive while RARRAY_CONST_PTR(tmp) is used by rb_str_format. [alan: sunk the guard below usage] Reviewed-by: Alan Wu <XrXr@users.noreply.github.com>
1 parent aec8563 commit a9b84ad

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

string.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,9 @@ rb_str_format_m(VALUE str, VALUE arg)
26402640
VALUE tmp = rb_check_array_type(arg);
26412641

26422642
if (!NIL_P(tmp)) {
2643-
return rb_str_format(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), str);
2643+
VALUE result = rb_str_format(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), str);
2644+
RB_GC_GUARD(tmp);
2645+
return result;
26442646
}
26452647
return rb_str_format(1, &arg, str);
26462648
}

0 commit comments

Comments
 (0)