Skip to content

Commit 50ec831

Browse files
ryo1katobradfitz
authored andcommitted
bufio: Use maxConsecutiveEmptyReads instead of 100
Use maxConsecutiveEmptyReads const instead of hardcoded 100 in scan.go too. Change-Id: I993f353a3748f0d6bdefab38bf5cb224eea8a969 Reviewed-on: https://go-review.googlesource.com/46915 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
1 parent cea92e8 commit 50ec831

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/bufio/scan.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ var ErrFinalToken = errors.New("final token")
123123
// After Scan returns false, the Err method will return any error that
124124
// occurred during scanning, except that if it was io.EOF, Err
125125
// will return nil.
126-
// Scan panics if the split function returns 100 empty tokens without
127-
// advancing the input. This is a common error mode for scanners.
126+
// Scan panics if the split function returns too many empty
127+
// tokens without advancing the input. This is a common error mode for
128+
// scanners.
128129
func (s *Scanner) Scan() bool {
129130
if s.done {
130131
return false
@@ -156,8 +157,8 @@ func (s *Scanner) Scan() bool {
156157
} else {
157158
// Returning tokens not advancing input at EOF.
158159
s.empties++
159-
if s.empties > 100 {
160-
panic("bufio.Scan: 100 empty tokens without progressing")
160+
if s.empties > maxConsecutiveEmptyReads {
161+
panic("bufio.Scan: too many empty tokens without progressing")
161162
}
162163
}
163164
return true

0 commit comments

Comments
 (0)