Browse Source

* Patch from Gilson Nunes, Silvio Clecio to fix unsafe typecast, improved loop logic (Bug ID 29812)

git-svn-id: trunk@33215 -
michael 9 years ago
parent
commit
2717fd67d6
1 changed files with 9 additions and 2 deletions
  1. 9 2
      packages/fcl-pdf/src/fppdf.pp

+ 9 - 2
packages/fcl-pdf/src/fppdf.pp

@@ -2713,10 +2713,17 @@ end;
 function TPDFDocument.IndexOfGlobalXRef(const AValue: string): integer;
 function TPDFDocument.IndexOfGlobalXRef(const AValue: string): integer;
 var
 var
   i: integer;
   i: integer;
+  p : TPDFObject;
 begin
 begin
-  for i:=1 to Pred(FGlobalXRefs.Count) do
-    if TPDFName(GetX(i).Dict.Elements[0].Value).Name=AValue then
+  Result:=-1;
+  I:=0;
+  While (Result=-1) and (I<FGlobalXRefs.Count) do
+    begin
+    p:=GetX(i).Dict.Elements[0].Value;
+    if (p is TPDFName) and (TPDFName(p).Name=AValue) then
       Result:=i;
       Result:=i;
+    Inc(I);    
+    end;
 end;
 end;
 
 
 function TPDFDocument.FindGlobalXRef(const AName: String): TPDFXRef;
 function TPDFDocument.FindGlobalXRef(const AName: String): TPDFXRef;