mirror of https://github.com/golang/go.git
scan: for style, adjust code for bad scan read counts
Make the code more consistent with the rest of the file. Should have caught this in review of CL 225357. Change-Id: I12824cb436539c31604684e043ebb7587cc92471 Reviewed-on: https://go-review.googlesource.com/c/go/+/225557 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
93bcf91299
commit
2975b27bbd
|
|
@ -69,6 +69,7 @@ var (
|
||||||
ErrTooLong = errors.New("bufio.Scanner: token too long")
|
ErrTooLong = errors.New("bufio.Scanner: token too long")
|
||||||
ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
|
ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
|
||||||
ErrAdvanceTooFar = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
|
ErrAdvanceTooFar = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
|
||||||
|
ErrBadReadCount = errors.New("bufio.Scanner: Read returned impossible count")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -211,9 +212,9 @@ func (s *Scanner) Scan() bool {
|
||||||
// be extra careful: Scanner is for safe, simple jobs.
|
// be extra careful: Scanner is for safe, simple jobs.
|
||||||
for loop := 0; ; {
|
for loop := 0; ; {
|
||||||
n, err := s.r.Read(s.buf[s.end:len(s.buf)])
|
n, err := s.r.Read(s.buf[s.end:len(s.buf)])
|
||||||
if n < 0 || n > len(s.buf)-s.end {
|
if n < 0 || len(s.buf)-s.end < n {
|
||||||
n = 0
|
s.setErr(ErrBadReadCount)
|
||||||
err = errors.New("bufio.Scanner: Read returned impossible count")
|
break
|
||||||
}
|
}
|
||||||
s.end += n
|
s.end += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue