aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2020-03-26 09:32:27 +1100
committerRob Pike <r@golang.org>2020-03-25 22:44:57 +0000
commit2975b27bbd3d4e85a2488ac289e112bc0dedfebe (patch)
treedf3cb26caab9c6ccc83b369367a383587feab790 /src
parent93bcf912994931780cdd4f5492ae8fcfdf760208 (diff)
downloadgo-2975b27bbd3d4e85a2488ac289e112bc0dedfebe.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/bufio/scan.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/bufio/scan.go b/src/bufio/scan.go
index 976b5994eb..af46a14fbb 100644
--- a/src/bufio/scan.go
+++ b/src/bufio/scan.go
@@ -69,6 +69,7 @@ var (
ErrTooLong = errors.New("bufio.Scanner: token too long")
ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
ErrAdvanceTooFar = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
+ ErrBadReadCount = errors.New("bufio.Scanner: Read returned impossible count")
)
const (
@@ -211,9 +212,9 @@ func (s *Scanner) Scan() bool {
// be extra careful: Scanner is for safe, simple jobs.
for loop := 0; ; {
n, err := s.r.Read(s.buf[s.end:len(s.buf)])
- if n < 0 || n > len(s.buf)-s.end {
- n = 0
- err = errors.New("bufio.Scanner: Read returned impossible count")
+ if n < 0 || len(s.buf)-s.end < n {
+ s.setErr(ErrBadReadCount)
+ break
}
s.end += n
if err != nil {