summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/string.c b/string.c
index ae157f474e..248813e233 100644
--- a/string.c
+++ b/string.c
@@ -144,8 +144,14 @@ str_new4(klass, str)
RSTRING(str2)->len = RSTRING(str)->len;
RSTRING(str2)->ptr = RSTRING(str)->ptr;
- RSTRING(str)->aux.shared = str2;
- FL_SET(str, ELTS_SHARED);
+ if (FL_TEST(str, ELTS_SHARED) && !RSTRING(str)->aux.shared) {
+ /* ptr should be null_str */
+ FL_SET(str2, ELTS_SHARED);
+ }
+ else {
+ FL_SET(str, ELTS_SHARED);
+ RSTRING(str)->aux.shared = str2;
+ }
OBJ_INFECT(str2, str);
return str2;