Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,12 @@ rb_ary_pop(VALUE ary)
{
ary_resize_capa(ary, n * 2);
}
--n;
ARY_SET_LEN(ary, n);

VALUE obj = RARRAY_AREF(ary, n - 1);

ARY_SET_LEN(ary, n - 1);
ary_verify(ary);
return RARRAY_AREF(ary, n);
return obj;
}

/*
Expand Down
2 changes: 2 additions & 0 deletions internal/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ RARRAY_AREF(VALUE ary, long i)
VALUE val;
RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);

RUBY_ASSERT(i < RARRAY_LEN(ary));

RBIMPL_WARNING_PUSH();
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 13
RBIMPL_WARNING_IGNORED(-Warray-bounds);
Expand Down
1 change: 1 addition & 0 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ rb_feature_p(vm_ns_t *vm_ns, const char *feature, const char *ext, int rb, int e
index = rb_darray_get(feature_indexes, i);
}

if (index >= RARRAY_LEN(features)) continue;
v = RARRAY_AREF(features, index);
f = StringValuePtr(v);
if ((n = RSTRING_LEN(v)) < len) continue;
Expand Down
10 changes: 7 additions & 3 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3332,9 +3332,10 @@ method_inspect(VALUE method)
for (int i = 0; i < RARRAY_LEN(params); i++) {
pair = RARRAY_AREF(params, i);
kind = RARRAY_AREF(pair, 0);
name = RARRAY_AREF(pair, 1);
// FIXME: in tests it turns out that kind, name = [:req] produces name to be false. Why?..
if (NIL_P(name) || name == Qfalse) {
if (RARRAY_LEN(pair) > 1) {
name = RARRAY_AREF(pair, 1);
}
else {
// FIXME: can it be reduced to switch/case?
if (kind == req || kind == opt) {
name = rb_str_new2("_");
Expand All @@ -3348,6 +3349,9 @@ method_inspect(VALUE method)
else if (kind == nokey) {
name = rb_str_new2("nil");
}
else {
name = Qnil;
}
}

if (kind == req) {
Expand Down
2 changes: 1 addition & 1 deletion vm_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ rb_backtrace_to_location_ary(VALUE self)
VALUE
rb_location_ary_to_backtrace(VALUE ary)
{
if (!RB_TYPE_P(ary, T_ARRAY) || !rb_frame_info_p(RARRAY_AREF(ary, 0))) {
if (!RB_TYPE_P(ary, T_ARRAY) || RARRAY_LEN(ary) == 0 || !rb_frame_info_p(RARRAY_AREF(ary, 0))) {
return Qfalse;
}

Expand Down