diff options
| author | Tomoyuki Sahara <[email protected]> | 2017-06-15 10:53:01 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-06-15 10:53:01 +0900 |
| commit | 7c62d89348e4fb4258e177bb434582edd18ffdd4 (patch) | |
| tree | 29ca5c04ea47dbb9d9a777294fbfe417182f4cbe | |
| parent | fe99819bc996891ea97c10446ca3e495c77d790f (diff) | |
| parent | 3642fe40131220520e961157fa501ee1adf2ebca (diff) | |
| download | mruby-7c62d89348e4fb4258e177bb434582edd18ffdd4.tar.gz mruby-7c62d89348e4fb4258e177bb434582edd18ffdd4.zip | |
Merge pull request #88 from christopheraue/master
Fix for IO#read(n) with n > IO::BUF_SIZE
| -rw-r--r-- | mrblib/io.rb | 10 | ||||
| -rw-r--r-- | test/io.rb | 7 |
2 files changed, 13 insertions, 4 deletions
diff --git a/mrblib/io.rb b/mrblib/io.rb index 3ea839379..f538af490 100644 --- a/mrblib/io.rb +++ b/mrblib/io.rb @@ -205,10 +205,12 @@ class IO break end - if length && length <= @buf.size - array.push @buf[0, length] - @buf = @buf[length, @buf.size - length] - break + if length + consume = (length <= @buf.size) ? length : @buf.size + array.push @buf[0, consume] + @buf = @buf[consume, @buf.size - consume] + length -= consume + break if length == 0 else array.push @buf @buf = '' diff --git a/test/io.rb b/test/io.rb index f1dd7afe8..5a6dbf146 100644 --- a/test/io.rb +++ b/test/io.rb @@ -140,6 +140,13 @@ assert('IO#read', '15.2.20.5.14') do end end +assert "IO#read(n) with n > IO::BUF_SIZE" do + r,w = IO.pipe + n = IO::BUF_SIZE+1 + w.write 'a'*n + assert_equal r.read(n), 'a'*n +end + assert('IO#readchar', '15.2.20.5.15') do # almost same as IO#getc IO.open(IO.sysopen($mrbtest_io_rfname)) do |io| |
