[前][次][番号順一覧][スレッド一覧]

ruby-changes:74493

From: Peter <ko1@a...>
Date: Tue, 15 Nov 2022 07:03:56 +0900 (JST)
Subject: [ruby-changes:74493] 710c1ada84 (master): Use string's capacity to determine if reembeddable

https://git.ruby-lang.org/ruby.git/commit/?id=710c1ada84

From 710c1ada8494859a6902c0baf8566d474c34ce32 Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Mon, 14 Nov 2022 16:59:43 -0500
Subject: 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.
---
 string.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/string.c b/string.c
index ca2cb4525e..73be76cd72 100644
--- a/string.c
+++ b/string.c
@@ -258,7 +258,7 @@ rb_str_size_as_embedded(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L258
     /* 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
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]