diff --git a/Src/DSInternals.Common.Test/Cryptography/SortedFileSearcherTester.cs b/Src/DSInternals.Common.Test/Cryptography/SortedFileSearcherTester.cs index 2c4472e..a2c0220 100644 --- a/Src/DSInternals.Common.Test/Cryptography/SortedFileSearcherTester.cs +++ b/Src/DSInternals.Common.Test/Cryptography/SortedFileSearcherTester.cs @@ -141,7 +141,7 @@ Zulu"; // Find first Assert.IsTrue(searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75")); - // Find last + // Find last Assert.IsTrue(searcher.FindString("1AE189A6FFF7DB51548F12F063491E36")); // Find middle @@ -229,7 +229,13 @@ Zulu"; // Find middle Assert.IsTrue(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2")); - // Find non-existing + // Find non-existing (before first) + Assert.IsFalse(searcher.FindString("0AE188AB6DF35626E09C77F2880CAD75")); + + // Find non-existing (in the middle) + Assert.IsFalse(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F1")); + + // Find non-existing (after last) Assert.IsFalse(searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2")); } } diff --git a/Src/DSInternals.Common/Cryptography/SortedFileSearcher.cs b/Src/DSInternals.Common/Cryptography/SortedFileSearcher.cs index 73cde4a..a03a9a4 100644 --- a/Src/DSInternals.Common/Cryptography/SortedFileSearcher.cs +++ b/Src/DSInternals.Common/Cryptography/SortedFileSearcher.cs @@ -49,6 +49,12 @@ // Read the current line string line = this.reader.ReadLine(); + if(line == null) + { + // We have reached the end of the file, so the search is over + break; + } + switch (String.Compare(line, 0, query, 0, query.Length, true)) { case -1: