Przeglądaj źródła

* prevent a range check error in TFPList.IndexOfItem when searching backwards in
an empty list and the compiler is compiled with range checking turned on

git-svn-id: trunk@49406 -

nickysn 4 lat temu
rodzic
commit
d5a0dd3d25
1 zmienionych plików z 9 dodań i 6 usunięć
  1. 9 6
      compiler/cclasses.pas

+ 9 - 6
compiler/cclasses.pas

@@ -883,15 +883,18 @@ begin
   else
     begin
       Result:=-1;
-      psrc:=@FList^[FCount-1];
-      For Index:=FCount-1 downto 0 Do
+      if FCount>0 then
         begin
-          if psrc^=Item then
+          psrc:=@FList^[FCount-1];
+          For Index:=FCount-1 downto 0 Do
             begin
-              Result:=Index;
-              exit;
+              if psrc^=Item then
+                begin
+                  Result:=Index;
+                  exit;
+                end;
+              dec(psrc);
             end;
-          dec(psrc);
         end;
     end;
 end;