From 85bbacbba2defb1118fff2a43a6ae7295ccebbba Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 12 Jun 2014 11:33:12 +0000 Subject: [PATCH] string.c: consider capacity * string.c (rb_str_resize): should consider the capacity instead of the old length, as pointed out by nagachika. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 48ba5a0851..4756fd48c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jun 12 20:32:28 2014 Nobuyoshi Nakada + + * string.c (rb_str_resize): should consider the capacity instead + of the old length, as pointed out by nagachika. + Thu Jun 12 18:31:01 2014 SHIBATA Hiroshi * lib/net/http/responses.rb: added Net::HTTPPermanentRedirect(308) diff --git a/string.c b/string.c index 8a349cb6c0..faf12f23e8 100644 --- a/string.c +++ b/string.c @@ -1996,7 +1996,7 @@ rb_str_resize(VALUE str, long len) if (len == slen) return str; str_make_independent_expand(str, len - slen); } - else if (slen < len || slen - len > 1024) { + else if (slen < len || (RSTRING(str)->as.heap.aux.capa - len) > (len < 1024 ? len : 1024)) { REALLOC_N(RSTRING(str)->as.heap.ptr, char, len + termlen); } else if (len == slen) return str;