summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2022-03-12 16:30:52 +0900
committernagachika <nagachika@ruby-lang.org>2022-03-12 16:30:52 +0900
commit7c0537906314f0c2a317b37661ccdec8dddc6277 (patch)
tree998fa4138b4767d90bdd5af798be696089182c3c /io.c
parentf2d996dcff56057b48ae41ab6f23e7654848ea4b (diff)
merge revision(s) fdf39963490cf2cf95b30d91bb9b35964c2c2350: [Backport #18421]
Empty and return the buffer if zero size is given [Bug #18421] In `IO#readpartial` and `IO#read_nonblock`, as well as `IO#read`. --- io.c | 8 ++++++-- test/ruby/test_io.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-)
Diffstat (limited to 'io.c')
-rw-r--r--io.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/io.c b/io.c
index 521b0b0e9a..9720aed06e 100644
--- a/io.c
+++ b/io.c
@@ -2982,8 +2982,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);
@@ -3126,8 +3128,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) {