From 0e84de2b9830e3b752ba5f8d97aa3c38924aafc5 Mon Sep 17 00:00:00 2001 From: naruse Date: Sat, 14 Apr 2012 18:02:01 +0000 Subject: merge revision(s) 34785,35095,35098,35111,35152: [Backport #6294] * io.c (set_binary_mode_with_seek_cur): reorder function qualifiers. * test/ruby/test_io.rb (TestIO#test_pos_with_getc): added. see [Bug #6179][ruby-core:43518] * test/ruby/test_io.rb (TestIO#test_pos_with_getc): updated. see [ruby-core:43550] * io.c (static int io_fflush): add the definition. Use it in set_binary_mode_with_seek_cur(). * io.c (set_binary_mode_with_seek_cur): refactoring to split the content into io_unread(). Fix the possibility of buffer overflow. * io.c (io_unread): add new implementation for Windows. Previous one caused invalid cursor position using IO#pos with OS text mode. New one fixes the bug. * test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_dont_move_cursor_position): add a test for above bug. [ruby-core:43497] [Bug #6179] * io.c (io_unread): fixed memory leak. report by nagachika via IRC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 24 ++++++++++++++++++++++++ test/ruby/test_io_m17n.rb | 15 +++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index bb6f239509..edf449dd5c 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1307,6 +1307,30 @@ class TestIO < Test::Unit::TestCase end end + def test_pos_with_getc + bug6179 = '[ruby-core:43497]' + t = make_tempfile + ["", "t", "b"].each do |mode| + open(t.path, "w#{mode}") do |f| + f.write "0123456789\n" + end + + open(t.path, "r#{mode}") do |f| + assert_equal 0, f.pos, "mode=r#{mode}" + assert_equal '0', f.getc, "mode=r#{mode}" + assert_equal 1, f.pos, "mode=r#{mode}" + assert_equal '1', f.getc, "mode=r#{mode}" + assert_equal 2, f.pos, "mode=r#{mode}" + assert_equal '2', f.getc, "mode=r#{mode}" + assert_equal 3, f.pos, "mode=r#{mode}" + assert_equal '3', f.getc, "mode=r#{mode}" + assert_equal 4, f.pos, "mode=r#{mode}" + assert_equal '4', f.getc, "mode=r#{mode}" + end + end + end + + def test_sysseek t = make_tempfile diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 2f71356f8e..c6cff18957 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -2347,4 +2347,19 @@ EOT } assert_equal(paths.map(&:encoding), encs, bug6072) end + + def test_pos_dont_move_cursor_position + bug6179 = '[ruby-core:43497]' + with_tmpdir { + str = "line one\r\nline two\r\nline three\r\n" + generate_file("tmp", str) + open("tmp", "r") do |f| + assert_equal("line one\n", f.readline) + assert_equal(10, f.pos, bug6179) + assert_equal("line two\n", f.readline, bug6179) + assert_equal(20, f.pos, bug6179) + assert_equal("line three\n", f.readline, bug6179) + end + } + end if /mswin|mingw/ =~ RUBY_PLATFORM end -- cgit v1.2.3