From bdd26d33cae36b4a42bb8ae38a180bc310c5af6b Mon Sep 17 00:00:00 2001 From: Bastiaan Veelo Date: Fri, 1 Sep 2023 11:33:25 +0100 Subject: [PATCH] Prevent slicing beyond bounds. Apply same fix as in #325. Fixes #333 ArraySliceError. --- pegged/peg.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pegged/peg.d b/pegged/peg.d index 2e9d98a..e0548cb 100644 --- a/pegged/peg.d +++ b/pegged/peg.d @@ -1927,7 +1927,7 @@ template longest_match(rules...) if (rules.length > 0) foreach(i; 0..rules.length) if (failedLength[i] == maxFailedLength && results[i].matches.length > 0) errString ~= results[i].matches[$-1] ~ names[i][] ~ " or "; - orErrorString = errString[0..$-4]; + orErrorString = errString[0..$ >= 4 ? $-4 : $]; longestFail.matches = longestFail.matches.length == 0 ? [orErrorString] : longestFail.matches[0..$-1] // discarding longestFail error message