[ruby-cvs:63466] usa:r56301 (ruby_2_2): merge revision(s) 55547, 55551, 55552, 55555, 55557, 55559, 55568, 55575, 55691: [Backport #12536]

usa at ruby-lang.org usa at ruby-lang.org
Sat Oct 1 00:42:12 JST 2016


usa	2016-10-01 00:42:12 +0900 (Sat, 01 Oct 2016)

  New Revision: 56301

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56301

  Log:
    merge revision(s) 55547,55551,55552,55555,55557,55559,55568,55575,55691: [Backport #12536]
    
    * string.c: Fix memory corruptions when using UTF-16/32 strings.
      [Bug #12536] [ruby-dev:49699]
    
    * string.c (TERM_LEN_MAX): Macro for the longest TERM_FILL length,
      the same as largest value of rb_enc_mbminlen(enc) among encodings.
    
    * string.c (str_new, rb_str_buf_new, str_shared_replace): Allocate
      +TERM_LEN_MAX bytes instead of +1. This change may increase memory
      usage.
    
    * string.c (rb_str_new_with_class): Use TERM_LEN of the "obj".
    
    * string.c (rb_str_plus, rb_str_justify): Use str_new0 which is aware
      of termlen.
    
    * string.c (str_shared_replace): Copy +termlen bytes instead of +1.
    
    * string.c (rb_str_times): termlen should not be included in capa.
    
    * string.c (RESIZE_CAPA_TERM): When using RSTRING_EMBED_LEN_MAX,
      termlen should be counted with it because embedded strings are
      also processed by TERM_FILL.
    
    * string.c (rb_str_capacity, str_shared_replace, str_buf_cat): ditto.
    
    * string.c (rb_str_drop_bytes, rb_str_setbyte, str_byte_substr): ditto.
    
    * string.c (rb_str_subseq, str_substr): When RSTRING_EMBED_LEN_MAX
      is used, TERM_LEN(str) should be considered with it because
      embedded strings are also processed by TERM_FILL.
      Additional fix for [Bug #12536] [ruby-dev:49699].
      Additional fix for [Bug #12536] [ruby-dev:49699].
    
    * string.c (rb_usascii_str_new, rb_utf8_str_new): Specify termlen
      which is apparently 1 for the encodings.
    
    * string.c (str_new0_cstr): New static function to create a String
      object from a C string with specifying termlen.
    
    * string.c (rb_usascii_str_new_cstr, rb_utf8_str_new_cstr): Specify
      termlen by using new str_new0_cstr().
    
    * string.c (str_new_static): Specify termlen from the given encoding
      when creating a new String object is needed.
    
    * string.c (rb_tainted_str_new_with_enc): New function to create a
      tainted String object with the given encoding. This means that
      the termlen is correctly specified. Curretly static function.
      The function name might be renamed to rb_tainted_enc_str_new
      or rb_enc_tainted_str_new.
    
    * string.c (rb_external_str_new_with_enc): Use encoding by using the
      above rb_tainted_str_new_with_enc().
    
    * string.c (str_fill_term): When termlen increases, re-allocation
      of memory for termlen should always be needed.
      In this fix, if possible, decrease capa instead of realloc.
      [Bug #12536] [ruby-dev:49699]
    
    * string.c: Partially reverts r55547 and r55555.
      ChangeLog about the reverted changes are also deleted in this file.
      [Bug #12536] [ruby-dev:49699] [ruby-dev:49702]
    
    * string.c: Specify termlen as far as possible.
      the termlen is correctly specified. Currently static function.
    
    * string.c (rb_str_change_terminator_length): New function to change
      termlen and resize heap for the terminator. This is split from
      rb_str_fill_terminator (str_fill_term) because filling terminator
      and changing terminator length are different things. [Bug #12536]
    
    * internal.h: declaration for rb_str_change_terminator_length.
    
    * string.c (str_fill_term): Simplify only to zero-fill the terminator.
      For non-shared strings, it assumes that (capa + termlen) bytes of
      heap is allocated. This partially reverts r55557.
    
    * encoding.c (rb_enc_associate_index): rb_str_change_terminator_length
      is used, and it should be called whenever the termlen is changed.
    
    * string.c (str_capacity): New static function to return capacity
      of a string with the given termlen, because the termlen may
      sometimes be different from TERM_LEN(str) especially during
      changing termlen or filling terminator with specific termlen.
    
    * string.c (rb_str_capacity): Use str_capacity.
    
    * string.c (str_buf_cat): Fix capa size for embed string.
      Fix bug in r55547. [Bug #12536]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/encoding.c
    branches/ruby_2_2/string.c
    branches/ruby_2_2/version.h


More information about the ruby-cvs mailing list