1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

present: dont crash if address searched backwards

For /start/,/end/, the /end/ address can wrap around and match somewhere
before /start/. Handle this case without crashing.

Fixes golang/go#7163.

Change-Id: I6fc3b5048e88728c9403a1d1e284ea8ada567a1e
Reviewed-on: https://go-review.googlesource.com/21182
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Dominik Honnef 2016-03-26 08:48:56 +01:00 committed by Rob Pike
parent 86ad1193da
commit 5ffc3249d3

View File

@ -89,6 +89,11 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele
if err != nil { if err != nil {
return nil, fmt.Errorf("%s:%d: %v", sourceFile, sourceLine, err) return nil, fmt.Errorf("%s:%d: %v", sourceFile, sourceLine, err)
} }
if lo > hi {
// The search in addrToByteRange can wrap around so we might
// end up with the range ending before its starting point
hi, lo = lo, hi
}
// Acme pattern matches can stop mid-line, // Acme pattern matches can stop mid-line,
// so run to end of line in both directions if not at line start/end. // so run to end of line in both directions if not at line start/end.