From aaa509dd076e7de654a6c555bec264083c145388 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sun, 18 Aug 2019 19:44:00 +0900 Subject: Also use `str_init_shared` for `orig` in `str_make_shared()` --- src/string.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/string.c') diff --git a/src/string.c b/src/string.c index ab53c2e69..10e20c3b1 100644 --- a/src/string.c +++ b/src/string.c @@ -77,7 +77,7 @@ str_init_shared(mrb_state *mrb, const struct RString *orig, struct RString *s, m } else { shared = (mrb_shared_string *)mrb_malloc(mrb, sizeof(mrb_shared_string)); - shared->refcnt = 2; + shared->refcnt = 1; shared->ptr = orig->as.heap.ptr; shared->len = orig->as.heap.len; } @@ -516,7 +516,7 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n) static void str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s) { - mrb_int len = RSTR_LEN(orig); + size_t len = (size_t)orig->as.heap.len; mrb_assert(!RSTR_EMBED_P(orig)); if (RSTR_NOFREE_P(orig)) { @@ -536,8 +536,7 @@ str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s) orig->as.heap.ptr = (char *)mrb_realloc(mrb, orig->as.heap.ptr, len+1); } str_init_shared(mrb, orig, s, NULL); - orig->as.heap.aux.shared = s->as.heap.aux.shared; - RSTR_SET_TYPE_FLAG(orig, SHARED); + str_init_shared(mrb, orig, orig, s->as.heap.aux.shared); } } -- cgit v1.2.3