summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2025-11-01 10:49:14 -0400
committerPeter Zhu <peter@peterzhu.ca>2025-11-02 09:17:17 -0500
commitdba4c9fbe79bdc3b7679330760d2b27d29a9911a (patch)
tree84d59466b7cbcf16dd8de581594b1681e63e4379
parentbd51b20c50a9a05c9fcea8025b223892eed4165b (diff)
Fix string allocation when slot size < 40 bytes
We need to allocate at least sizeof(struct RString) when the string is embedded on garbage collectors that support slot sizes less than 40 bytes.
-rw-r--r--string.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/string.c b/string.c
index fa6ce7f3ec..2a250cc69d 100644
--- a/string.c
+++ b/string.c
@@ -242,7 +242,9 @@ rb_str_reembeddable_p(VALUE str)
static inline size_t
rb_str_embed_size(long capa)
{
- return offsetof(struct RString, as.embed.ary) + capa;
+ size_t size = offsetof(struct RString, as.embed.ary) + capa;
+ if (size < sizeof(struct RString)) size = sizeof(struct RString);
+ return size;
}
size_t