* check whether there are any elements at all for both TStack<> and TQueue<> before removing any

git-svn-id: trunk@46843 -
This commit is contained in:
svenbarth 2020-09-11 15:46:43 +00:00
parent 6efd9cc93f
commit cda338b893

View File

@ -2021,6 +2021,9 @@ end;
function TQueue<T>.DoRemove(AIndex: SizeInt; ACollectionNotification: TCollectionNotification): T; function TQueue<T>.DoRemove(AIndex: SizeInt; ACollectionNotification: TCollectionNotification): T;
begin begin
if Count = 0 then
raise EArgumentOutOfRangeException.CreateRes(@SArgumentOutOfRange);
Result := FItems[AIndex]; Result := FItems[AIndex];
FItems[AIndex] := Default(T); FItems[AIndex] := Default(T);
Inc(FLow); Inc(FLow);
@ -2151,7 +2154,7 @@ end;
function TStack<T>.DoRemove(AIndex: SizeInt; ACollectionNotification: TCollectionNotification): T; function TStack<T>.DoRemove(AIndex: SizeInt; ACollectionNotification: TCollectionNotification): T;
begin begin
if AIndex < 0 then if (AIndex < 0) or (Count = 0) then
raise EArgumentOutOfRangeException.CreateRes(@SArgumentOutOfRange); raise EArgumentOutOfRangeException.CreateRes(@SArgumentOutOfRange);
Result := FItems[AIndex]; Result := FItems[AIndex];