Skip to content

Commit 67d2d02

Browse files
authored
Merge pull request kennyledet#524 from panderson54/master
Issue 523
2 parents 0f9730f + e53d24b commit 67d2d02

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)