diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-21 05:28:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-21 05:28:38 +0000 |
commit | f0e6e47999a23f1b4f69b4695f70b1e2a8d41e93 (patch) | |
tree | dc572f7624c84047cf19ef263b1a17b25174d07d /string.c | |
parent | c8d66b5d829f8ba029ae967cf67982d754e30591 (diff) | |
download | ruby-f0e6e47999a23f1b4f69b4695f70b1e2a8d41e93.tar.gz |
string.c: use the usable size
* string.c (rb_str_change_terminator_length): when called after
the content has been copied, old terminator length no longer
makes sense. use the whole usable size instead of capacity
without terminator. [ruby-core:80257] [Bug #13339]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -2102,11 +2102,11 @@ str_fill_term(VALUE str, char *s, long len, int termlen) void rb_str_change_terminator_length(VALUE str, const int oldtermlen, const int termlen) { - long capa = str_capacity(str, oldtermlen); + long capa = str_capacity(str, oldtermlen) + oldtermlen; long len = RSTRING_LEN(str); assert(capa >= len); - if (capa - len < termlen - oldtermlen) { + if (capa - len < termlen) { rb_check_lockedtmp(str); str_make_independent_expand(str, len, 0L, termlen); } @@ -2118,7 +2118,7 @@ rb_str_change_terminator_length(VALUE str, const int oldtermlen, const int terml if (!STR_EMBED_P(str)) { /* modify capa instead of realloc */ assert(!FL_TEST((str), STR_SHARED)); - RSTRING(str)->as.heap.aux.capa = capa - (termlen - oldtermlen); + RSTRING(str)->as.heap.aux.capa = capa - termlen; } if (termlen > oldtermlen) { TERM_FILL(RSTRING_PTR(str) + len, termlen); |