Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,8 @@ rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy)
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
rb_str_set_len(z->buf, RSTRING_LEN(z->buf) + filled);
if (!NIL_P(z->buf))
rb_str_set_len(z->buf, RSTRING_LEN(z->buf) + filled);

return Qnil;
}
Expand Down
7 changes: 7 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def test_params
z.close # without this, outputs `zlib(finalizer): the stream was freed prematurely.'
end

def test_params_before_output
z = Zlib::Deflate.new
EnvUtil.suppress_warning {z.params(Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY)}
z << "foo"
assert_equal("foo", Zlib::Inflate.inflate(z.finish))
end

def test_set_dictionary
z = Zlib::Deflate.new
z.set_dictionary("foo")
Expand Down