diff options
author | Peter Zhu <[email protected]> | 2022-11-14 16:59:43 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2022-11-14 16:59:43 -0500 |
commit | 710c1ada8494859a6902c0baf8566d474c34ce32 (patch) | |
tree | 7fe79e2cb653ceb0950f18f4a94281b948e77f0d /string.c | |
parent | 9a6c3355c5c9541b9afb94d4ee770a7584c7ac15 (diff) |
Use string's capacity to determine if reembeddable
During auto-compaction, using length to determine whether or not a
string can be re-embedded may be a problem for newly created strings.
This is because usually it requires a malloc before setting the length.
If the malloc triggers compaction, then the string may be re-embedded
and can cause crashes.
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -258,7 +258,7 @@ rb_str_size_as_embedded(VALUE str) /* if the string is not currently embedded, but it can be embedded, how * much space would it require */ else if (rb_str_reembeddable_p(str)) { - real_size = rb_str_embed_size(RSTRING(str)->as.heap.len) + TERM_LEN(str); + real_size = rb_str_embed_size(RSTRING(str)->as.heap.aux.capa) + TERM_LEN(str); } else { #endif |