فهرست منبع

Rewrite CommandLine creation in Dos.Exec function to avoid problems when ComLine is 255 characters long

git-svn-id: trunk@34015 -
pierre 9 سال پیش
والد
کامیت
7efce7f121
1فایلهای تغییر یافته به همراه29 افزوده شده و 14 حذف شده
  1. 29 14
      rtl/win/dos.pp

+ 29 - 14
rtl/win/dos.pp

@@ -280,9 +280,11 @@ var
   SI: TStartupInfo;
   PI: TProcessInformation;
   l    : Longint;
-  CommandLine : array[0..511] of char;
-  AppParam : array[0..255] of char;
-  pathlocal : string;
+  { Maximum length of both short string is
+    2x255 = 510, plus possibly two double-quotes,
+    two spaces and the final #0, makes 515 chars }
+  CommandLine : array[0..515] of char;
+  has_no_double_quote : boolean;
 begin
   DosError:=0;
   FillChar(SI, SizeOf(SI), 0);
@@ -293,18 +295,31 @@ begin
     do it if there are already double quotes, since Win32 does not
     like double quotes which are duplicated!
   }
-  if pos('"',path) = 0 then
-    pathlocal:='"'+path+'"'
+  has_no_double_quote:=pos('"',path)=0;
+  if has_no_double_quote then
+    begin
+      CommandLine[0]:='"';
+      l:=1;
+    end
   else
-    pathlocal := path;
-  Move(Pathlocal[1],CommandLine,length(Pathlocal));
-
-  AppParam[0]:=' ';
-  AppParam[1]:=' ';
-  Move(ComLine[1],AppParam[2],length(Comline));
-  AppParam[Length(ComLine)+2]:=#0;
-  { concatenate both pathnames }
-  Move(Appparam[0],CommandLine[length(Pathlocal)],strlen(Appparam)+1);
+    l:=0;
+  Move(Path[1],CommandLine[l],length(Path));
+  l:=l+length(Path);
+  if has_no_double_quote then
+    begin
+      CommandLine[l]:='"';
+      inc(l);
+    end;
+  { Add two spaces }
+  CommandLine[l]:=' ';
+  inc(l);
+  CommandLine[l]:=' ';
+  inc(l);
+  { Add comline string }
+  Move(ComLine[1],CommandLine[l],length(Comline));
+  l:=l+length(ComLine);
+  { Terminate string }
+  CommandLine[l]:=#0;
   if not CreateProcess(nil, PChar(@CommandLine),
            Nil, Nil, ExecInheritsHandles,$20, Nil, Nil, SI, PI) then
    begin