summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/string.c b/string.c
index 25b325f0ec..692a158c09 100644
--- a/string.c
+++ b/string.c
@@ -157,14 +157,17 @@ rb_str_new4(orig)
{
VALUE klass, str;
+ if (OBJ_FROZEN(orig)) return orig;
klass = rb_obj_class(orig);
if (FL_TEST(orig, ELTS_SHARED) && RSTRING(orig)->aux.shared) {
long ofs;
str = RSTRING(orig)->aux.shared;
ofs = RSTRING(str)->len - RSTRING(orig)->len;
- str = str_new3(klass, str);
- RSTRING(str)->ptr += ofs;
- RSTRING(str)->len -= ofs;
+ if (ofs > 0) {
+ str = str_new3(klass, str);
+ RSTRING(str)->ptr += ofs;
+ RSTRING(str)->len -= ofs;
+ }
}
else if (FL_TEST(orig, STR_ASSOC)) {
str = str_new(klass, RSTRING(orig)->ptr, RSTRING(orig)->len);