mirror of
https://github.com/golang/go.git
synced 2025-11-11 14:11:04 +00:00
bufio: bulletproof UnreadRune
After a fill(), there is nothing to back up. Make sure UnreadRune recognizes the situation. Fixes #1137. (Stops the crash, but doesn't make UnreadRune usable after a Peek()). R=rsc CC=golang-dev https://golang.org/cl/2498041
This commit is contained in:
parent
d6df301774
commit
52e3c99cfb
2 changed files with 10 additions and 1 deletions
|
|
@ -564,3 +564,12 @@ func TestPeek(t *testing.T) {
|
|||
t.Fatalf("want EOF got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeekThenUnreadRune(t *testing.T) {
|
||||
// This sequence used to cause a crash.
|
||||
r := NewReader(strings.NewReader("x"))
|
||||
r.ReadRune()
|
||||
r.Peek(1)
|
||||
r.UnreadRune()
|
||||
r.ReadRune() // Used to panic here
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue