summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2026-01-28 13:39:33 +0100
committerJean Boussier <jean.boussier@gmail.com>2026-01-29 23:32:04 +0100
commit91619f0230c0e5a95c796c1bd4f784c151e15614 (patch)
treeb8cf37fc6092a51f318996f382ab9503ba390100 /string.c
parent457bb11aa5b2ce4424b611acb489686d130261de (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 'string.c')
-rw-r--r--string.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/string.c b/string.c
index a36eb6e9f3..3cfc77600b 100644
--- a/string.c
+++ b/string.c
@@ -1559,7 +1559,7 @@ rb_str_tmp_frozen_no_embed_acquire(VALUE orig)
}
RSTRING(str)->len = RSTRING(orig)->len;
- RSTRING(str)->as.heap.aux.capa = capa;
+ RSTRING(str)->as.heap.aux.capa = capa + (TERM_LEN(orig) - TERM_LEN(str));
return str;
}
@@ -3135,7 +3135,7 @@ str_subseq(VALUE str, long beg, long len)
const int termlen = TERM_LEN(str);
if (!SHARABLE_SUBSTRING_P(beg, len, RSTRING_LEN(str))) {
- str2 = rb_str_new(RSTRING_PTR(str) + beg, len);
+ str2 = rb_enc_str_new(RSTRING_PTR(str) + beg, len, rb_str_enc_get(str));
RB_GC_GUARD(str);
return str2;
}
@@ -7814,7 +7814,7 @@ mapping_buffer_free(void *p)
while (current_buffer) {
previous_buffer = current_buffer;
current_buffer = current_buffer->next;
- ruby_sized_xfree(previous_buffer, previous_buffer->capa);
+ ruby_sized_xfree(previous_buffer, offsetof(mapping_buffer, space) + previous_buffer->capa);
}
}