diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-09-10 14:42:02 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-09-11 08:14:25 -0400 |
| commit | 5a946a5be29a099ddaff55b52b5c2ab0cbe61ca1 (patch) | |
| tree | 62fd379685b9708d225197b7f8db8dddda2c8aa3 /array.c | |
| parent | 729d602e290a3d986c8fc3d178cf1e56f93a88a4 (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.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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; } /* |
