cmd/digraph: use ReadString rather than bufio.Scanner
if an input line is too long (more than bufio.MaxScanTokenSize), bufio.Scanner returns bufio.ErrToolong.
Use bufio's ReadString instead.
Fixes golang.org/go#57807
Change-Id: If4165213668a468b844ee6a0ae84263475504208
GitHub-Last-Rev: e7057d029edcf3b51b1b54c820a2eafc1566de0f
GitHub-Pull-Request: golang/tools#423
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462053
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
diff --git a/cmd/digraph/digraph.go b/cmd/digraph/digraph.go
index 69d84ad..0e50ad1 100644
--- a/cmd/digraph/digraph.go
+++ b/cmd/digraph/digraph.go
@@ -351,20 +351,29 @@
g := make(graph)
var linenum int
- in := bufio.NewScanner(rd)
- for in.Scan() {
+ // We avoid bufio.Scanner as it imposes a (configurable) limit
+ // on line length, whereas Reader.ReadString does not.
+ in := bufio.NewReader(rd)
+ for {
linenum++
+ line, err := in.ReadString('\n')
+ eof := false
+ if err == io.EOF {
+ eof = true
+ } else if err != nil {
+ return nil, err
+ }
// Split into words, honoring double-quotes per Go spec.
- words, err := split(in.Text())
+ words, err := split(line)
if err != nil {
return nil, fmt.Errorf("at line %d: %v", linenum, err)
}
if len(words) > 0 {
g.addEdges(words[0], words[1:]...)
}
- }
- if err := in.Err(); err != nil {
- return nil, err
+ if eof {
+ break
+ }
}
return g, nil
}
diff --git a/cmd/digraph/digraph_test.go b/cmd/digraph/digraph_test.go
index cff4673..60b8e75 100644
--- a/cmd/digraph/digraph_test.go
+++ b/cmd/digraph/digraph_test.go
@@ -45,6 +45,7 @@
{"scss", g2, "sccs", nil, "c d\ne\n"},
{"scc", g2, "scc", []string{"d"}, "c\nd\n"},
{"succs", g2, "succs", []string{"a"}, "b\nc\n"},
+ {"succs-long-token", g2 + "x " + strings.Repeat("x", 96*1024), "succs", []string{"x"}, strings.Repeat("x", 96*1024) + "\n"},
{"preds", g2, "preds", []string{"c"}, "a\nd\n"},
{"preds multiple args", g2, "preds", []string{"c", "d"}, "a\nb\nc\nd\n"},
} {