From a06adb176f3c0d44b15ff41fa7788ae408147df2 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 18 Aug 2017 23:40:27 +0900 Subject: `mrb_str_cat`: `capa` should be bigger than `total`. --- src/string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/string.c b/src/string.c index c5efd779f..e382b470c 100644 --- a/src/string.c +++ b/src/string.c @@ -2566,15 +2566,15 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len) mrb_raise(mrb, E_ARGUMENT_ERROR, "string size too big"); } if (capa <= total) { - while (total > capa) { + while (capa <= total) { if (capa <= MRB_INT_MAX / 2) { capa *= 2; } else { - capa = total; + capa = total+1; } } - if (capa < total || capa > MRB_INT_MAX) { + if (capa <= total || capa > MRB_INT_MAX) { goto size_error; } resize_capa(mrb, s, capa); -- cgit v1.2.3