Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ strio_unget_bytes(struct StringIO *ptr, const char *cp, rb_len_t cl)
if (rest > cl) memset(s + len, 0, rest - cl);
pos -= cl;
}
memcpy(s + pos, (cp ? cp : s), cl);
memmove(s + pos, (cp ? cp : s), cl);
ptr->pos = pos;
return Qnil;
}
Expand Down
18 changes: 18 additions & 0 deletions test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,24 @@ def test_ungetc_same_string
assert_match(/\A(?:abc){30}bc(?:abc){6}\z/, s.string)
end

def test_ungetc_same_string_past_end
s = StringIO.new("abc", "r+")
s.pos = 4
s.ungetc(s.string)
assert_equal("aabc", s.string)
assert_equal(1, s.pos)
end

def test_ungetc_same_string_after_reallocation
original = "abc" * 1024
expected = original + original.byteslice(1..)
s = StringIO.new(original, "r+")
s.pos = 1
s.ungetc(s.string)
assert_equal(expected, s.string)
assert_equal(0, s.pos)
end

def test_ungetbyte_pos
b = '\\b00010001 \\B00010001 \\b1 \\B1 \\b000100011'
s = StringIO.new( b )
Expand Down
Loading