summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-29 07:00:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-29 07:00:25 +0000
commit6f65a0ebf28ae362f99e0b38473b9105a4c5093d (patch)
tree1d3bbcb867d162347506f344176107c6673194b8
parent149dadf368981bdd026dd0e86278cc86d74d48a6 (diff)
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
-rw-r--r--ChangeLog5
-rw-r--r--string.c15
2 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 53ee9e3c17..0c2b43dc75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jul 29 16:00:22 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (str_buf_cat): consider empty non-embed string case,
+ not to loop infinitely. [ruby-core:70074] [Bug #11383]
+
Wed Jul 29 15:25:19 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_eval.c (send_internal): set method_missing_reason before
diff --git a/string.c b/string.c
index 0a8f4e1d9c..026ebd7147 100644
--- a/string.c
+++ b/string.c
@@ -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);