Skip to content

Commit dba4c9f

Browse files
committed
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.
1 parent bd51b20 commit dba4c9f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

string.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ rb_str_reembeddable_p(VALUE str)
242242
static inline size_t
243243
rb_str_embed_size(long capa)
244244
{
245-
return offsetof(struct RString, as.embed.ary) + capa;
245+
size_t size = offsetof(struct RString, as.embed.ary) + capa;
246+
if (size < sizeof(struct RString)) size = sizeof(struct RString);
247+
return size;
246248
}
247249

248250
size_t

0 commit comments

Comments
 (0)