From 52efca767eb4b73f331b93091a8891945d812555 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 17 Jul 2022 21:14:20 -0700 Subject: [PATCH] Make sure start/end not reset --- BurnOutSharp/Matching/ContentMatch.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/BurnOutSharp/Matching/ContentMatch.cs b/BurnOutSharp/Matching/ContentMatch.cs index 71a697a7..90d41cb2 100644 --- a/BurnOutSharp/Matching/ContentMatch.cs +++ b/BurnOutSharp/Matching/ContentMatch.cs @@ -51,13 +51,17 @@ namespace BurnOutSharp.Matching if (Needle.Length > stack.Length) return (false, -1); - // If start or end are not set properly, set them to defaults - if (Start < 0) - Start = 0; - if (End < 0) - End = stack.Length - Needle.Length; + // Set the default start and end values + int start = Start; + int end = End; - for (int i = reverse ? End : Start; reverse ? i > Start : i < End; i += reverse ? -1 : 1) + // If start or end are not set properly, set them to defaults + if (start < 0) + start = 0; + if (end < 0) + end = stack.Length - Needle.Length; + + for (int i = reverse ? end : start; reverse ? i > start : i < end; i += reverse ? -1 : 1) { // If we somehow have an invalid end and we haven't matched, return if (i > stack.Length)