* guard agains empty arrays in a few tArrayHelper binsearch methods

fixes bug #39761

(cherry picked from commit 4710281936)
This commit is contained in:
marcoonthegit 2022-06-05 18:03:28 +02:00
parent dbf1d63fff
commit 745e109411

View File

@ -1055,6 +1055,13 @@ class function TArrayHelper<T>.BinarySearch(constref AValues: array of T; constr
var
imin, imax, imid: Int32;
begin
if Length(AValues) = 0 then
begin
ASearchResult.CompareResult := 0;
ASearchResult.FoundIndex := -1;
ASearchResult.CandidateIndex := -1;
Exit(False);
end;
// continually narrow search until just one element remains
imin := AIndex;
imax := Pred(AIndex + ACount);
@ -1119,6 +1126,12 @@ var
imin, imax, imid: Int32;
LCompare: SizeInt;
begin
if Length(AValues) = 0 then
begin
AFoundIndex := -1;
Exit(False);
end;
// continually narrow search until just one element remains
imin := AIndex;
imax := Pred(AIndex + ACount);