Skip to content

Commit

Permalink
internal/match: fix panic at EOF when TraceDFA > 0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jba authored and rsc committed Jan 27, 2021
1 parent 6523801 commit 5aa300f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/match/rematch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5aa300f

Please sign in to comment.