diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-11-01 10:49:14 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-11-02 09:17:17 -0500 |
| commit | dba4c9fbe79bdc3b7679330760d2b27d29a9911a (patch) | |
| tree | 84d59466b7cbcf16dd8de581594b1681e63e4379 | |
| parent | bd51b20c50a9a05c9fcea8025b223892eed4165b (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.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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 |
