diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-12-22 15:33:12 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-12-22 15:45:59 +0900 |
commit | fdf39963490cf2cf95b30d91bb9b35964c2c2350 (patch) | |
tree | 42794b7b89e46b0a035fda9ebbbe5ea22336bcc8 /io.c | |
parent | 9902398d8613ac4eaf9b90c3d2c1a103a32d61e2 (diff) |
Empty and return the buffer if zero size is given [Bug #18421]
In `IO#readpartial` and `IO#read_nonblock`, as well as `IO#read`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5323
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -3161,8 +3161,10 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int no_exception, int nonblock) GetOpenFile(io, fptr); rb_io_check_byte_readable(fptr); - if (len == 0) + if (len == 0) { + io_set_read_length(str, 0, shrinkable); return str; + } if (!nonblock) READ_CHECK(fptr); @@ -3305,8 +3307,10 @@ io_read_nonblock(rb_execution_context_t *ec, VALUE io, VALUE length, VALUE str, GetOpenFile(io, fptr); rb_io_check_byte_readable(fptr); - if (len == 0) + if (len == 0) { + io_set_read_length(str, 0, shrinkable); return str; + } n = read_buffered_data(RSTRING_PTR(str), len, fptr); if (n <= 0) { |