From 5aa300fd3333d0c6592148249397338023cafcce Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Thu, 14 Jan 2021 10:20:23 -0500 Subject: [PATCH] internal/match: fix panic at EOF when TraceDFA > 0 With TraceDFA > 0, Scan sometimes panics by indexing a slice with a negative value. This fixes the panic. The fix is trivial: index the slice with a variable that was already adjusted non-negative for the purpose but not used. --- internal/match/rematch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/match/rematch.go b/internal/match/rematch.go index 878a5db..3dca29c 100644 --- a/internal/match/rematch.go +++ b/internal/match/rematch.go @@ -936,7 +936,7 @@ Words: if start < 0 { start = 0 } - println("DFA ran out of input at «", text[words[i-10].Lo:], "|", "EOF", "»\n") + println("DFA ran out of input at «", text[words[start].Lo:], "|", "EOF", "»\n") } return match, end }