Browse Source

* Ansistring versions of MkDir,ChDir,RmDir: make a full copy of argument string. This is necessary because underlying implementations can modify directory separators in argument, causing crash if argument resides in read-only memory. This is also consistent with shortstring variants of same procedures.

git-svn-id: trunk@23000 -
sergei 12 years ago
parent
commit
186cbaaf18
1 changed files with 12 additions and 6 deletions
  1. 12 6
      rtl/objpas/objpas.pp

+ 12 - 6
rtl/objpas/objpas.pp

@@ -88,9 +88,9 @@ Var
 {$endif FPC_HAS_FEATURE_COMMANDARGS}
 
 {$ifdef FPC_HAS_FEATURE_FILEIO}
-     Procedure MkDir(const s:ansistring);overload;
-     Procedure RmDir(const s:ansistring);overload;
-     Procedure ChDir(const s:ansistring);overload;
+     Procedure MkDir(s:ansistring);overload;
+     Procedure RmDir(s:ansistring);overload;
+     Procedure ChDir(s:ansistring);overload;
 {$endif FPC_HAS_FEATURE_FILEIO}
 
 {****************************************************************************
@@ -245,18 +245,24 @@ end;
 
 
 {$ifdef FPC_HAS_FEATURE_FILEIO}
-Procedure MkDir(const s:ansistring);[IOCheck];
+{ xxDirPChar procedures can adjust directory separators in supplied string (at least
+  Windows implementation does so). Therefore full copy of argument is needed,
+  just passing by value isn't enough because it won't copy a string literal. }
+Procedure MkDir(s:ansistring);[IOCheck];
 begin
+  UniqueString(s);
   mkdirpchar(pchar(s),length(s));
 end;
 
-Procedure RmDir(const s:ansistring);[IOCheck];
+Procedure RmDir(s:ansistring);[IOCheck];
 begin
+  UniqueString(s);
   RmDirpchar(pchar(s),length(s));
 end;
 
-Procedure ChDir(const s:ansistring);[IOCheck];
+Procedure ChDir(s:ansistring);[IOCheck];
 begin
+  UniqueString(s);
   ChDirpchar(pchar(s),length(s));
 end;
 {$endif FPC_HAS_FEATURE_FILEIO}