Browse Source

* 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 years ago
parent
commit
d5a0dd3d25
1 changed files with 9 additions and 6 deletions
  1. 9 6
      compiler/cclasses.pas

+ 9 - 6
compiler/cclasses.pas

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