Bläddra i källkod

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

git-svn-id: trunk@46843 -
svenbarth 4 år sedan
förälder
incheckning
cda338b893
1 ändrade filer med 4 tillägg och 1 borttagningar
  1. 4 1
      packages/rtl-generics/src/generics.collections.pas

+ 4 - 1
packages/rtl-generics/src/generics.collections.pas

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