diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2026-01-28 13:39:33 +0100 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2026-01-29 23:32:04 +0100 |
| commit | 91619f0230c0e5a95c796c1bd4f784c151e15614 (patch) | |
| tree | b8cf37fc6092a51f318996f382ab9503ba390100 /array.c | |
| parent | 457bb11aa5b2ce4424b611acb489686d130261de (diff) | |
gc.c: Verify provided size in `rb_gc_impl_free`
For now the provided size is just for GC statistics, but in the future
we may want to forward it to C23's `free_sized` and passing an incorrect
size to it is undefined behavior.
Diffstat (limited to 'array.c')
| -rw-r--r-- | array.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -387,13 +387,14 @@ rb_ary_make_embedded(VALUE ary) if (!ARY_EMBED_P(ary)) { const VALUE *buf = ARY_HEAP_PTR(ary); long len = ARY_HEAP_LEN(ary); + long capa = ARY_HEAP_CAPA(ary); FL_SET_EMBED(ary); ARY_SET_EMBED_LEN(ary, len); MEMCPY((void *)ARY_EMBED_PTR(ary), (void *)buf, VALUE, len); - ary_heap_free_ptr(ary, buf, len * sizeof(VALUE)); + ary_heap_free_ptr(ary, buf, capa * sizeof(VALUE)); } } @@ -428,7 +429,7 @@ ary_resize_capa(VALUE ary, long capacity) if (len > capacity) len = capacity; MEMCPY((VALUE *)RARRAY(ary)->as.ary, ptr, VALUE, len); - ary_heap_free_ptr(ary, ptr, old_capa); + ary_heap_free_ptr(ary, ptr, old_capa * sizeof(VALUE)); FL_SET_EMBED(ary); ARY_SET_LEN(ary, len); |
