From: Austin Clements Date: Mon, 17 Nov 2014 19:44:41 +0000 (-0500) Subject: cmd/pprof: fix EOF handling when getting function source X-Git-Tag: go1.5beta1~2710 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=38fef031e16f819a3f1f6e14e3e7d70ac4ccfebb;p=gostls13.git cmd/pprof: fix EOF handling when getting function source getFunctionSource gathers five lines of "margin" around every requested sample line. However, if this margin went past the end of the source file, getFunctionSource would encounter an io.EOF error and abort with this error, resulting in listings like (pprof) list main.main ROUTINE ======================== main.main in ... 0 8.33s (flat, cum) 99.17% of Total Error: EOF (pprof) Modify the error handling in getFunctionSource so io.EOF is always considered non-fatal. If it reaches EOF, it simply returns the lines it has. LGTM=bradfitz R=rsc, bradfitz CC=golang-codereviews https://golang.org/cl/172600043 --- diff --git a/src/cmd/pprof/internal/report/source.go b/src/cmd/pprof/internal/report/source.go index 57300dd91a..73ae1b4ea2 100644 --- a/src/cmd/pprof/internal/report/source.go +++ b/src/cmd/pprof/internal/report/source.go @@ -358,9 +358,13 @@ func getFunctionSource(fun, file string, fns nodes, start, end int) (nodes, stri for { line, err := buf.ReadString('\n') if err != nil { - if line == "" || err != io.EOF { + if err != io.EOF { return nil, file, err } + if line == "" { + // end was at or past EOF; that's okay + break + } } if lineno >= start { flat, cum := sumNodes(lineNodes[lineno])