* string.c (tr_trans): adjust buffer size by processed and rest
  lengths, instead of doubling repeatedly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-06-16 03:17:54 +00:00
Родитель cc9f1e9195
Коммит 1cbc622ea7
2 изменённых файлов: 9 добавлений и 6 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Thu Jun 16 12:17:52 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (tr_trans): adjust buffer size by processed and rest
lengths, instead of doubling repeatedly.
Thu Jun 16 11:15:25 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Jun 16 11:15:25 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (tr_trans): consider terminator length and fix heap * string.c (tr_trans): consider terminator length and fix heap

Просмотреть файл

@ -6342,9 +6342,8 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
c = c0; c = c0;
if (enc != e1) may_modify = 1; if (enc != e1) may_modify = 1;
} }
while (t - buf + tlen >= max) { if ((offset = t - buf) + tlen > max) {
offset = t - buf; max = offset + tlen + (send - s);
max *= 2;
REALLOC_N(buf, char, max + termlen); REALLOC_N(buf, char, max + termlen);
t = buf + offset; t = buf + offset;
} }
@ -6415,9 +6414,8 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
c = c0; c = c0;
if (enc != e1) may_modify = 1; if (enc != e1) may_modify = 1;
} }
while (t - buf + tlen >= max) { if ((offset = t - buf) + tlen > max) {
offset = t - buf; max = offset + tlen + (long)((send - s) * 1.2);
max *= 2;
REALLOC_N(buf, char, max + termlen); REALLOC_N(buf, char, max + termlen);
t = buf + offset; t = buf + offset;
} }