summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-21 07:38:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-21 07:38:16 +0000
commit3a6bb56029c3890d39577b96179a9f869e7cef84 (patch)
treecfb7d1981564e332457f9e187f07794e2a37c798 /string.c
parent82727299777de8f218d3d8c258650d6c7d4098a4 (diff)
Fix garbage allocation
* string.c (rb_str_casemap): do not put code with side effects inside RSTRING_PTR() macro which evaluates the argument multiple times. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/string.c b/string.c
index a62ae2dd8d..e4f0293bb8 100644
--- a/string.c
+++ b/string.c
@@ -5811,12 +5811,14 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc)
if (buffer_count==1) {
target = rb_str_new_with_class(source, (const char*)current_buffer->space, target_length);
- xfree(current_buffer);
+ xfree(current_buffer);
}
else {
- char *target_current = RSTRING_PTR(target = rb_str_new_with_class(source, 0, target_length));
+ char *target_current;
mapping_buffer *previous_buffer;
+ target = rb_str_new_with_class(source, 0, target_length);
+ target_current = RSTRING_PTR(target);
current_buffer=pre_buffer.next;
while (current_buffer) {
memcpy(target_current, current_buffer->space, current_buffer->used);