* 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
This commit is contained in:
nobu 2016-06-21 07:38:16 +00:00
Родитель 8272729977
Коммит 3a6bb56029
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Tue Jun 21 16:38:14 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_casemap): do not put code with side effects
inside RSTRING_PTR() macro which evaluates the argument multiple
times.
Tue Jun 21 16:13:45 2016 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_str_casemap): fix memory leak.

Просмотреть файл

@ -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);