TAChart: Fix crash when a ListChartSource contains a single point and that has X=NaN. Add corresponding unit test.

This commit is contained in:
wp_xyz 2023-05-06 13:03:59 +02:00
parent 06c1648f61
commit e8f8aa16ce
2 changed files with 26 additions and 2 deletions

View File

@ -1124,10 +1124,20 @@ procedure TCustomChartSource.FindBounds(
AXMin, AXMax: Double; out ALB, AUB: Integer);
function FindLB(const X: Double; L, R: Integer): Integer;
var
xVal: Double;
begin
while L <= R do begin
Result := (R - L) div 2 + L;
if Item[Result]^.X < X then
xVal := Item[Result]^.X;
if IsNaN(xVal) then
begin
if (Result = 0) or (Result = Count-1) then
break
else
dec(L)
end else
if xVal < X then
L := Result + 1
else
R := Result - 1;
@ -1136,10 +1146,20 @@ procedure TCustomChartSource.FindBounds(
end;
function FindUB(const X: Double; L, R: Integer): Integer;
var
xVal: Double;
begin
while L <= R do begin
Result := (R - L) div 2 + L;
if Item[Result]^.X <= X then
xVal := Item[Result]^.X;
if IsNaN(xVal) then
begin
if (Result = 0) or (Result = Count-1) then
break
else
inc(R);
end else
if xVal <= X then
L := Result + 1
else
R := Result - 1;

View File

@ -344,6 +344,10 @@ begin
FSource.SetXValue(0, SafeNan);
Check2(2, 2, -1e100, 3);
Check2(2, 2, NegInfinity, 3);
FSource.Clear;
FSource.Add(SafeNaN, SafeNaN);
Check2(0, 0, NegInfinity, Infinity);
end;
procedure TListSourceTest.Cache;