diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-29 07:00:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-29 07:00:25 +0000 |
commit | 3e79293f054566730c124e67940896d93f6ae611 (patch) | |
tree | 1d3bbcb867d162347506f344176107c6673194b8 /string.c | |
parent | d22e721284775c07c1dba75e4341235f84a7a30a (diff) | |
download | ruby-3e79293f054566730c124e67940896d93f6ae611.tar.gz |
string.c: empty non-embed case
* string.c (str_buf_cat): consider empty non-embed string case,
not to loop infinitely. [ruby-core:70074] [Bug #11383]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -2292,12 +2292,17 @@ str_buf_cat(VALUE str, const char *ptr, long len) } total = olen + len; if (capa <= total) { - while (total > capa) { - if (capa > LONG_MAX / 2) { - capa = (total + 4095) / 4096 * 4096; - break; + if (LIKELY(capa > 0)) { + while (total > capa) { + if (capa > LONG_MAX / 2) { + capa = (total + 4095) / 4096 * 4096; + break; + } + capa = 2 * capa; } - capa = 2 * capa; + } + else { + capa = total; } RESIZE_CAPA_TERM(str, capa, termlen); sptr = RSTRING_PTR(str); |