mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-11 21:59:39 +02:00
TAChart: Fix crash when a ListChartSource contains a single point and that has X=NaN. Add corresponding unit test.
This commit is contained in:
parent
06c1648f61
commit
e8f8aa16ce
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user