From ebb6fcdad7b994cc8d05b91a2051b44e7500f46d Mon Sep 17 00:00:00 2001 From: Janico Greifenberg Date: Tue, 22 Jul 2008 19:55:45 +0200 Subject: [PATCH] StringIO#each_byte now checks the current position against the length of the contained string before delegating to String#each_byte. This avoids an error when calling the method when the current position is out of bounds. --- lib/stringio.rb | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/lib/stringio.rb b/lib/stringio.rb index bd777a4..bf45c88 100644 --- a/lib/stringio.rb +++ b/lib/stringio.rb @@ -115,7 +115,9 @@ class StringIO def each_byte raise IOError, "not opened for reading" unless @readable - @string[@pos..-1].each_byte { |b| @pos += 1; yield b} + if @pos < @string.length + @string[@pos..-1].each_byte { |b| @pos += 1; yield b} + end nil end -- 1.5.4.3