diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-03-15 17:40:50 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-03-16 10:00:02 -0400 |
commit | e0cf80d666d4b5df3229f030a16d10d21323508e (patch) | |
tree | f9b5cfb5a90fdd54eb8bf204e171745a792b0b42 /weakmap.c | |
parent | 671ddb1eee1334e3b5cc209ec4c981ae2d0ba9dc (diff) |
Fix incorrect size of WeakMap buffer
In wmap_final_func, j is the number of elements + 1 (since j also
includes the length at the 0th index), so we should resize the buffer
to size j and the new length is j - 1.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7536
Diffstat (limited to 'weakmap.c')
-rw-r--r-- | weakmap.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -163,8 +163,8 @@ wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing) return ST_DELETE; } if (j < i) { - SIZED_REALLOC_N(ptr, VALUE, j + 1, i); - ptr[0] = j; + SIZED_REALLOC_N(ptr, VALUE, j, i); + ptr[0] = j - 1; *value = (st_data_t)ptr; } return ST_CONTINUE; |