Browse Source

fixed InternalFindFirst to initialize out Rslt properly, also reverted some earlier changes leading to potential issues as Jonas pointed out

git-svn-id: trunk@25944 -
Károly Balogh 11 years ago
parent
commit
3b87e2c386
1 changed files with 12 additions and 4 deletions
  1. 12 4
      rtl/morphos/sysutils.pp

+ 12 - 4
rtl/morphos/sysutils.pp

@@ -329,10 +329,11 @@ var
   tmpFIB : PFileInfoBlock;
   tmpFIB : PFileInfoBlock;
   tmpDateTime: TDateTime;
   tmpDateTime: TDateTime;
   validFile: boolean;
   validFile: boolean;
-
+  SystemFileName: RawByteString;
 begin
 begin
   validFile:=false;
   validFile:=false;
-  tmpLock := Lock(PChar(PathConv(ToSingleByteFileSystemEncodedFileName(FileName))), SHARED_LOCK);
+  SystemFileName := PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
+  tmpLock := Lock(PChar(SystemFileName), SHARED_LOCK);
   
   
   if (tmpLock <> 0) then begin
   if (tmpLock <> 0) then begin
     new(tmpFIB);
     new(tmpFIB);
@@ -354,9 +355,11 @@ function FileExists (const FileName : RawByteString) : Boolean;
 var
 var
   tmpLock: LongInt;
   tmpLock: LongInt;
   tmpFIB : PFileInfoBlock;
   tmpFIB : PFileInfoBlock;
+  SystemFileName: RawByteString;
 begin
 begin
   result:=false;
   result:=false;
-  tmpLock := Lock(PChar(PathConv(ToSingleByteFileSystemEncodedFileName(FileName))), SHARED_LOCK);
+  SystemFileName := PathConv(ToSingleByteFileSystemEncodedFileName(FileName));
+  tmpLock := Lock(PChar(SystemFileName), SHARED_LOCK);
 
 
   if (tmpLock <> 0) then begin
   if (tmpLock <> 0) then begin
     new(tmpFIB);
     new(tmpFIB);
@@ -376,6 +379,9 @@ var
   validDate: boolean;
   validDate: boolean;
 begin
 begin
   result:=-1; { We emulate Linux/Unix behaviour, and return -1 on errors. }
   result:=-1; { We emulate Linux/Unix behaviour, and return -1 on errors. }
+  { Initialize out Rslt, this is a *MUST*, because of caller side magic in objpas/sysutils/filutil.inc }
+  fillchar(Rslt,sizeof(Rslt),0);
+
   tmpStr:=PathConv(ToSingleByteFileSystemEncodedFileName(Path));
   tmpStr:=PathConv(ToSingleByteFileSystemEncodedFileName(Path));
 
 
   { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
   { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
@@ -531,11 +537,13 @@ function DirectoryExists(const Directory: RawByteString): Boolean;
 var
 var
   tmpLock: LongInt;
   tmpLock: LongInt;
   FIB    : PFileInfoBlock;
   FIB    : PFileInfoBlock;
+  SystemDirName: RawByteString;
 begin
 begin
   result:=false;
   result:=false;
   if (Directory='') or (InOutRes<>0) then exit;
   if (Directory='') or (InOutRes<>0) then exit;
 
 
-  tmpLock:=Lock(PChar(PathConv(ToSingleByteFileSystemEncodedFileName(Directory))),SHARED_LOCK);
+  SystemDirName:=PathConv(ToSingleByteFileSystemEncodedFileName(Directory));
+  tmpLock:=Lock(PChar(SystemDirName),SHARED_LOCK);
   if tmpLock=0 then exit;
   if tmpLock=0 then exit;
 
 
   FIB:=nil; new(FIB);
   FIB:=nil; new(FIB);