Skip to content

Commit

Permalink
Merge pull request #739 from casperisfine/read-clear-buffer
Browse files Browse the repository at this point in the history
read: don't clear buffer when nothing can be read
  • Loading branch information
rhenium authored May 5, 2024
2 parents 97305cf + 0845299 commit d2d6a99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions ext/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1958,9 +1958,11 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
else
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
}
rb_str_set_len(str, 0);
if (ilen == 0)
return str;

if (ilen == 0) {
rb_str_set_len(str, 0);
return str;
}

VALUE io = rb_attr_get(self, id_i_io);

Expand Down
9 changes: 7 additions & 2 deletions test/openssl/test_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,17 @@ def test_read_with_outbuf

buf = +"garbage"
assert_equal :wait_readable, s2.read_nonblock(100, buf, exception: false)
assert_equal "", buf
assert_equal "garbage", buf

s1.close
buf = +"garbage"
assert_equal nil, s2.read(100, buf)
assert_nil s2.read(100, buf)
assert_equal "", buf

buf = +"garbage"
ret = s2.read(0, buf)
assert_same buf, ret
assert_equal "", ret
}
end

Expand Down

0 comments on commit d2d6a99

Please sign in to comment.