summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/string.c b/src/string.c
index ae2e5ccc8..b4746545a 100644
--- a/src/string.c
+++ b/src/string.c
@@ -121,6 +121,9 @@ mrb_str_buf_new(mrb_state *mrb, size_t capa)
static void
resize_capa(mrb_state *mrb, struct RString *s, size_t capacity)
{
+#if SIZE_MAX > MRB_INT_MAX
+ mrb_assert(capacity < MRB_INT_MAX);
+#endif
if (RSTR_EMBED_P(s)) {
if (RSTRING_EMBED_LEN_MAX < capacity) {
char *const tmp = (char *)mrb_malloc(mrb, capacity+1);
@@ -129,15 +132,12 @@ resize_capa(mrb_state *mrb, struct RString *s, size_t capacity)
RSTR_UNSET_EMBED_FLAG(s);
s->as.heap.ptr = tmp;
s->as.heap.len = len;
- s->as.heap.aux.capa = capacity;
+ s->as.heap.aux.capa = (mrb_int)capacity;
}
}
else {
-#if SIZE_MAX > MRB_INT_MAX
- mrb_assert(capacity <= MRB_INT_MAX);
-#endif
- s->as.heap.ptr = (char *)mrb_realloc(mrb, RSTR_PTR(s), capacity+1);
- s->as.heap.aux.capa = capacity;
+ s->as.heap.ptr = (char*)mrb_realloc(mrb, RSTR_PTR(s), capacity+1);
+ s->as.heap.aux.capa = (mrb_int)capacity;
}
}
@@ -169,7 +169,7 @@ str_buf_cat(mrb_state *mrb, struct RString *s, const char *ptr, size_t len)
capa *= 2;
}
else {
- goto size_error;
+ capa = total;
}
}
if (capa < total || capa > MRB_INT_MAX) {
@@ -669,7 +669,7 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
if (RSTR_SHARED_P(s)) {
mrb_shared_string *shared = s->as.heap.aux.shared;
- if (shared->refcnt == 1 && s->as.heap.ptr == shared->ptr) {
+ if (shared->nofree == 0 && shared->refcnt == 1 && s->as.heap.ptr == shared->ptr) {
s->as.heap.ptr = shared->ptr;
s->as.heap.aux.capa = shared->len;
RSTR_PTR(s)[s->as.heap.len] = '\0';