Skip to content

Commit

Permalink
Make string embad from shared
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed May 13, 2017
1 parent 171e732 commit bdb36b3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,20 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)

p = RSTR_PTR(s);
len = s->as.heap.len;
ptr = (char *)mrb_malloc(mrb, (size_t)len + 1);
if (len < RSTRING_EMBED_LEN_MAX) {
RSTR_SET_EMBED_FLAG(s);
RSTR_SET_EMBED_LEN(s, len);
ptr = RSTR_PTR(s);
}
else {
ptr = (char *)mrb_malloc(mrb, (size_t)len + 1);
s->as.heap.ptr = ptr;
s->as.heap.aux.capa = len;
}
if (p) {
memcpy(ptr, p, len);
}
ptr[len] = '\0';
s->as.heap.ptr = ptr;
s->as.heap.aux.capa = len;
str_decref(mrb, shared);
}
RSTR_UNSET_SHARED_FLAG(s);
Expand Down

0 comments on commit bdb36b3

Please sign in to comment.