Skip to content

Commit b74a7d3

Browse files
nobutmm1
authored andcommitted
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 Conflicts: ChangeLog
1 parent abacb94 commit b74a7d3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ rb_str_resize(VALUE str, long len)
20612061
if (len == slen) return str;
20622062
str_make_independent_expand(str, len - slen);
20632063
}
2064-
else if (slen < len || slen - len > 1024) {
2064+
else if (slen < len || (RSTRING(str)->as.heap.aux.capa - len) > (len < 1024 ? len : 1024)) {
20652065
REALLOC_N(RSTRING(str)->as.heap.ptr, char, len + termlen);
20662066
}
20672067
else if (len == slen) return str;

0 commit comments

Comments
 (0)