ruby-changes:44969
From: nobu <ko1@a...>
Date: Sat, 10 Dec 2016 17:26:44 +0900 (JST)
Subject: [ruby-changes:44969] nobu:r57042 (trunk): zlib.c: replace with substring
nobu 2016-12-10 17:26:40 +0900 (Sat, 10 Dec 2016) New Revision: 57042 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57042 Log: zlib.c: replace with substring * ext/zlib/zlib.c (zstream_discard_input): replace with unread portion substring, not modifying the input buffer directly. [ruby-core:78567] [Bug #13021] Modified files: trunk/ext/zlib/zlib.c trunk/test/zlib/test_zlib.rb Index: ext/zlib/zlib.c =================================================================== --- ext/zlib/zlib.c (revision 57041) +++ ext/zlib/zlib.c (revision 57042) @@ -879,9 +879,8 @@ zstream_discard_input(struct zstream *z, https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L879 z->input = Qnil; } else { - memmove(RSTRING_PTR(z->input), RSTRING_PTR(z->input) + len, - RSTRING_LEN(z->input) - len); - rb_str_resize(z->input, RSTRING_LEN(z->input) - len); + z->input = rb_str_substr(z->input, len, + RSTRING_LEN(z->input) - len); } } @@ -2406,9 +2405,7 @@ gzfile_read_raw_ensure(struct gzfile *gz https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2405 VALUE str; if (gz->io == Qundef) { /* Zlib.gunzip */ - if (NIL_P(gz->z.input)) - rb_bug("unexpected condition: both gz->io and gz->z.input are nil"); - if (RSTRING_LEN(gz->z.input) < size) + if (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size) rb_raise(cGzError, "unexpected end of string"); } while (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size) { Index: test/zlib/test_zlib.rb =================================================================== --- test/zlib/test_zlib.rb (revision 57041) +++ test/zlib/test_zlib.rb (revision 57042) @@ -1128,25 +1128,25 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L1128 end def test_gzip - actual = Zlib.gzip("foo") + actual = Zlib.gzip("foo".freeze) actual[4, 4] = "\x00\x00\x00\x00" # replace mtime actual[9] = "\xff" # replace OS expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*") assert_equal expected, actual - actual = Zlib.gzip("foo", 0) + actual = Zlib.gzip("foo".freeze, 0) actual[4, 4] = "\x00\x00\x00\x00" # replace mtime actual[9] = "\xff" # replace OS expected = %w[1f8b08000000000000ff010300fcff666f6f2165738c03000000].pack("H*") assert_equal expected, actual - actual = Zlib.gzip("foo", 9) + actual = Zlib.gzip("foo".freeze, 9) actual[4, 4] = "\x00\x00\x00\x00" # replace mtime actual[9] = "\xff" # replace OS expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*") assert_equal expected, actual - actual = Zlib.gzip("foo", 9, Zlib::FILTERED) + actual = Zlib.gzip("foo".freeze, 9, Zlib::FILTERED) actual[4, 4] = "\x00\x00\x00\x00" # replace mtime actual[9] = "\xff" # replace OS expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*") @@ -1155,7 +1155,7 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L1155 def test_gunzip src = %w[1f8b08000000000000034bcbcf07002165738c03000000].pack("H*") - assert_equal 'foo', Zlib.gunzip(src) + assert_equal 'foo', Zlib.gunzip(src.freeze) src = %w[1f8b08000000000000034bcbcf07002165738c03000001].pack("H*") assert_raise(Zlib::GzipFile::LengthError){ Zlib.gunzip(src) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/