summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2025-09-10 14:42:02 -0400
committerPeter Zhu <peter@peterzhu.ca>2025-09-11 08:14:25 -0400
commit5a946a5be29a099ddaff55b52b5c2ab0cbe61ca1 (patch)
tree62fd379685b9708d225197b7f8db8dddda2c8aa3 /array.c
parent729d602e290a3d986c8fc3d178cf1e56f93a88a4 (diff)
Change order of RARRAY_AREF and ARY_SET_LEN in rb_ary_pop
We should access the last element first before we shrink the length of the array.
Diffstat (limited to 'array.c')
-rw-r--r--array.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/array.c b/array.c
index 9f13b1bf51..d9dff28ad9 100644
--- a/array.c
+++ b/array.c
@@ -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;
}
/*