Skip to content

Commit

Permalink
* guard agains empty arrays in a few tArrayHelper binsearch methods
Browse files Browse the repository at this point in the history
    fixes bug #39761
  • Loading branch information
marcoonthegit committed Jun 5, 2022
1 parent 2df9dd9 commit 4710281
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/rtl-generics/src/generics.collections.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,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);
Expand Down Expand Up @@ -1121,6 +1128,12 @@ class function TArrayHelper<T>.BinarySearch(constref AValues: array of T; constr
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);
Expand Down

0 comments on commit 4710281

Please sign in to comment.