From 5ffc3249d341c947aa65178abbf2253ed49c9e03 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sat, 26 Mar 2016 08:48:56 +0100 Subject: [PATCH] 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 Reviewed-by: Rob Pike --- present/code.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/present/code.go b/present/code.go index edf2ee42..681aaa00 100644 --- a/present/code.go +++ b/present/code.go @@ -89,6 +89,11 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele if err != nil { 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, // so run to end of line in both directions if not at line start/end.