Commit 34a21dca authored by Robert Griesemer's avatar Robert Griesemer

undo CL 86220044 / 41388e58be65

bufio: undo incorrect bug fix

««« original CL description
bufio: fix potential endless loop in ReadByte

Fixes #7745.

LGTM=bradfitz, r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/86220044
»»»

LGTM=adg
R=r, adg
CC=golang-codereviews
https://golang.org/cl/85550045
parent b38fba21
......@@ -88,8 +88,7 @@ func (b *Reader) fill() {
b.r = 0
}
// Read new data: try a limited number of times.
for i := maxConsecutiveEmptyReads; i > 0; i-- {
// Read new data.
n, err := b.rd.Read(b.buf[b.w:])
if n < 0 {
panic(errNegativeRead)
......@@ -97,13 +96,7 @@ func (b *Reader) fill() {
b.w += n
if err != nil {
b.err = err
return
}
if n > 0 {
return
}
}
b.err = io.ErrNoProgress
}
func (b *Reader) readErr() error {
......@@ -158,9 +151,6 @@ func (b *Reader) Read(p []byte) (n int, err error) {
// Large read, empty buffer.
// Read directly into p to avoid copy.
n, b.err = b.rd.Read(p)
if n < 0 {
panic(errNegativeRead)
}
if n > 0 {
b.lastByte = int(p[n-1])
b.lastRuneSize = -1
......
......@@ -14,7 +14,6 @@ import (
"strings"
"testing"
"testing/iotest"
"time"
"unicode/utf8"
)
......@@ -175,34 +174,6 @@ func TestReader(t *testing.T) {
}
}
type zeroReader struct{}
func (zeroReader) Read(p []byte) (int, error) {
return 0, nil
}
func TestZeroReader(t *testing.T) {
var z zeroReader
r := NewReader(z)
c := make(chan error)
go func() {
_, err := r.ReadByte()
c <- err
}()
select {
case err := <-c:
if err == nil {
t.Error("error expected")
} else if err != io.ErrNoProgress {
t.Error("unexpected error:", err)
}
case <-time.After(time.Second):
t.Error("test timed out (endless loop in ReadByte?)")
}
}
// A StringReader delivers its data one string segment at a time via Read.
type StringReader struct {
data []string
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment