Skip to content

Commit 2380f69

Browse files
committed
Fix array allocation when slot size < 40 bytes
We need to allocate at least sizeof(struct RArray) when the array is embedded on garbage collectors that support slot sizes less than 40 bytes.
1 parent dba4c9f commit 2380f69

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

array.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ ary_embed_capa(VALUE ary)
194194
static size_t
195195
ary_embed_size(long capa)
196196
{
197-
return offsetof(struct RArray, as.ary) + (sizeof(VALUE) * capa);
197+
size_t size = offsetof(struct RArray, as.ary) + (sizeof(VALUE) * capa);
198+
if (size < sizeof(struct RArray)) size = sizeof(struct RArray);
199+
return size;
198200
}
199201

200202
static bool

0 commit comments

Comments
 (0)