Skip to content

Commit e53d24b

Browse files
committed
Issue 523, Boyer Moore Horspool String Search walked off end the array in the case where a needle was not in the haystack but it's component characters still existed in the haystuck thus not triggereing the initial short circuit
1 parent 52f0503 commit e53d24b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Boyer_Moore_Horspool/C#/Davipb/Horspool.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static int Find(string haystack, string needle)
3232

3333
int index = 0;
3434

35-
while (index <= haystack.Length - needle.Length)
35+
while (index < haystack.Length - needle.Length)
3636
{
3737
bool match = true;
3838

@@ -42,6 +42,10 @@ public static int Find(string haystack, string needle)
4242
{
4343
match = false;
4444
index += BadMatchTable[haystack[index + needle.Length - 1]];
45+
if (index >= haystack.Length)
46+
{
47+
break;
48+
}
4549
}
4650
}
4751

0 commit comments

Comments
 (0)