ruby-changes:67107
From: Csaba <ko1@a...>
Date: Tue, 10 Aug 2021 11:32:59 +0900 (JST)
Subject: [ruby-changes:67107] 8df1ace64a (master): Fix ARGF.read(length) short read [Bug #18074]
https://git.ruby-lang.org/ruby.git/commit/?id=8df1ace64a From 8df1ace64a7695c855bf0a774e3fd70edfab0bf3 Mon Sep 17 00:00:00 2001 From: Csaba Henk <csaba@r...> Date: Tue, 10 Aug 2021 01:07:06 +0200 Subject: Fix ARGF.read(length) short read [Bug #18074] --- io.c | 3 +-- test/ruby/test_argf.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/io.c b/io.c index bbecc42..4d5c3ac 100644 --- a/io.c +++ b/io.c @@ -12512,8 +12512,7 @@ argf_read(int argc, VALUE *argv, VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L12512 else if (argc >= 1) { long slen = RSTRING_LEN(str); if (slen < len) { - len -= slen; - argv[0] = LONG2NUM(len); + argv[0] = LONG2NUM(len - slen); goto retry; } } diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 7922e5a..76a2720 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -1110,4 +1110,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L1110 assert_raise(TypeError, bug11610) {gets} }; end + + def test_sized_read + [@t1, @t2, @t3].each { |t| + open(t.path, "wb") { |f| f.write "t" } + } + ruby('-e', "print ARGF.read(3).size", @t1.path, @t2.path, @t3.path) do |f| + assert_equal("3", f.read) + end + end end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/