Procházet zdrojové kódy

* envstr now returns empty string when index out of bounds

olle před 21 roky
rodič
revize
3f4eb52fec
2 změnil soubory, kde provedl 33 přidání a 24 odebrání
  1. 13 10
      rtl/macos/dos.pp
  2. 20 14
      rtl/unix/dos.pp

+ 13 - 10
rtl/macos/dos.pp

@@ -819,20 +819,23 @@ Var
   i : longint;
   p : ppchar;
 Begin
-  p:=envp;      {defined in system}
-  i:=1;
-  while (i<Index) and (p^<>nil) do
-    begin
-      inc(i);
-      inc(p);
-    end;
-  if p=nil then
+  if Index <= 0 then
     envstr:=''
   else
     begin
-      envstr:=strpas(p^) + '=' + strpas(p^+strlen(p^)+1)
+      p:=envp;      {defined in system}
+      i:=1;
+      while (i<Index) and (p^<>nil) do
+        begin
+          inc(i);
+          inc(p);
+        end;
+      if p=nil then
+        envstr:=''
+      else
+        envstr:=strpas(p^) + '=' + strpas(p^+strlen(p^)+1);
     end;
-End;
+end;
 
 
 function c_getenv(varname: PChar): PChar; {TODO perhaps move to a separate inc file.}

+ 20 - 14
rtl/unix/dos.pp

@@ -691,25 +691,28 @@ Begin
 End;
 
 
-
 Function EnvStr (Index: longint): String;
 Var
   i : longint;
   p : ppchar;
 Begin
-  p:=envp;      {defined in syslinux}
-  i:=1;
-  while (i<Index) and (p^<>nil) do
-   begin
-     inc(i);
-     inc(p);
-   end;
-  if p=nil then
-   envstr:=''
+  if Index <= 0 then
+    envstr:=''
   else
-   envstr:=strpas(p^)
-End;
-
+    begin
+      p:=envp;      {defined in syslinux}
+      i:=1;
+      while (i<Index) and (p^<>nil) do
+        begin
+          inc(i);
+          inc(p);
+        end;
+      if p=nil then
+        envstr:=''
+      else
+        envstr:=strpas(p^)
+    end;
+end;
 
 
 Function GetEnv(EnvVar: String): String;
@@ -833,7 +836,10 @@ End.
 
 {
   $Log$
-  Revision 1.32  2004-03-14 18:42:39  peter
+  Revision 1.33  2004-07-25 22:46:34  olle
+    * envstr now returns empty string when index out of bounds
+
+  Revision 1.32  2004/03/14 18:42:39  peter
     * reset searchrec info in findfirst
 
   Revision 1.31  2004/03/04 22:15:16  marco