mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-10 16:19:29 +02:00
* guard agains empty arrays in a few tArrayHelper binsearch methods
fixes bug #39761
(cherry picked from commit 4710281936
)
This commit is contained in:
parent
dbf1d63fff
commit
745e109411
@ -1055,6 +1055,13 @@ class function TArrayHelper<T>.BinarySearch(constref AValues: array of T; constr
|
|||||||
var
|
var
|
||||||
imin, imax, imid: Int32;
|
imin, imax, imid: Int32;
|
||||||
begin
|
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
|
// continually narrow search until just one element remains
|
||||||
imin := AIndex;
|
imin := AIndex;
|
||||||
imax := Pred(AIndex + ACount);
|
imax := Pred(AIndex + ACount);
|
||||||
@ -1119,6 +1126,12 @@ var
|
|||||||
imin, imax, imid: Int32;
|
imin, imax, imid: Int32;
|
||||||
LCompare: SizeInt;
|
LCompare: SizeInt;
|
||||||
begin
|
begin
|
||||||
|
if Length(AValues) = 0 then
|
||||||
|
begin
|
||||||
|
AFoundIndex := -1;
|
||||||
|
Exit(False);
|
||||||
|
end;
|
||||||
|
|
||||||
// continually narrow search until just one element remains
|
// continually narrow search until just one element remains
|
||||||
imin := AIndex;
|
imin := AIndex;
|
||||||
imax := Pred(AIndex + ACount);
|
imax := Pred(AIndex + ACount);
|
||||||
|
Loading…
Reference in New Issue
Block a user