diff options
| author | Csaba Henk <csaba@redhat.com> | 2021-08-10 01:07:06 +0200 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-08-10 11:32:45 +0900 |
| commit | 8df1ace64a7695c855bf0a774e3fd70edfab0bf3 (patch) | |
| tree | eca9074744ad99e5f9a463eb94cd435510773b44 | |
| parent | 510c3655c9789f93e799499cd7923461e2743ec0 (diff) | |
Fix ARGF.read(length) short read [Bug #18074]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4727
| -rw-r--r-- | io.c | 3 | ||||
| -rw-r--r-- | test/ruby/test_argf.rb | 9 |
2 files changed, 10 insertions, 2 deletions
@@ -12512,8 +12512,7 @@ argf_read(int argc, VALUE *argv, VALUE argf) 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 7922e5ad07..76a2720d47 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -1110,4 +1110,13 @@ class TestArgf < Test::Unit::TestCase 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 |
