mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: fix wrong capa
* string.c (rb_str_resize): update capa only when buffer get reallocated. http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
308960a44e
commit
9729275473
2 changed files with 10 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
Sat Jun 14 10:52:15 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_resize): update capa only when buffer get
|
||||
reallocated.
|
||||
http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413
|
||||
|
||||
Sat Jun 14 08:28:59 2014 Zachary Scott <e@zzak.io>
|
||||
|
||||
* man/rake.1: [DOC] Update links for Rake, patch by @hsbt [Bug #9904]
|
||||
|
|
6
string.c
6
string.c
|
@ -1972,6 +1972,7 @@ rb_str_resize(VALUE str, long len)
|
|||
slen = RSTRING_LEN(str);
|
||||
|
||||
{
|
||||
long capa;
|
||||
const int termlen = TERM_LEN(str);
|
||||
if (STR_EMBED_P(str)) {
|
||||
if (len == slen) return str;
|
||||
|
@ -1996,11 +1997,12 @@ rb_str_resize(VALUE str, long len)
|
|||
if (len == slen) return str;
|
||||
str_make_independent_expand(str, len - slen);
|
||||
}
|
||||
else if (slen < len || (RSTRING(str)->as.heap.aux.capa - len) > (len < 1024 ? len : 1024)) {
|
||||
else if ((capa = RSTRING(str)->as.heap.aux.capa) < len ||
|
||||
(capa - len) > (len < 1024 ? len : 1024)) {
|
||||
REALLOC_N(RSTRING(str)->as.heap.ptr, char, len + termlen);
|
||||
RSTRING(str)->as.heap.aux.capa = len;
|
||||
}
|
||||
else if (len == slen) return str;
|
||||
RSTRING(str)->as.heap.aux.capa = len;
|
||||
RSTRING(str)->as.heap.len = len;
|
||||
TERM_FILL(RSTRING(str)->as.heap.ptr + len, termlen); /* sentinel */
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue