Bläddra i källkod

* pchar(pointer()) isms that were safe.

git-svn-id: trunk@8672 -
marco 18 år sedan
förälder
incheckning
827d380691
3 ändrade filer med 35 tillägg och 33 borttagningar
  1. 2 2
      rtl/objpas/sysutils/dati.inc
  2. 16 14
      rtl/objpas/sysutils/sysstr.inc
  3. 17 17
      rtl/unix/sysutils.pp

+ 2 - 2
rtl/objpas/sysutils/dati.inc

@@ -534,7 +534,7 @@ var
    var Len: integer;
    begin
    Len := Length(Str);
-   if ResultLen + Len < SizeOf(ResultBuffer) then begin
+   if ResultLen + Len < SizeOf(ResultBuffer) then begin // strmove not safe
       StrMove(ResultCurrent, pchar(Str), Len);
       ResultCurrent := ResultCurrent + Len;
       ResultLen := ResultLen + Len;
@@ -578,7 +578,7 @@ var
       tmp:integer;
 
    begin
-   FormatCurrent := Pchar(FormatStr);
+   FormatCurrent := Pchar(pointer(FormatStr));
    FormatEnd := FormatCurrent + Length(FormatStr);
    Clock12 := false;
    P := FormatCurrent;

+ 16 - 14
rtl/objpas/sysutils/sysstr.inc

@@ -72,8 +72,9 @@ Var
 
 begin
   Result := S;
+  if not assigned(pointer(result)) then exit;
   UniqueString(Result);
-  P:=Pchar(Result);
+  P:=Pchar(pointer(Result));
   for i := 1 to Length(Result) do
     begin
     if (P^ in ['a'..'z']) then P^ := char(byte(p^) - 32);
@@ -92,8 +93,9 @@ Var
 
 begin
   Result := S;
+  if not assigned(pointer(result)) then exit;
   UniqueString(Result);
-  P:=Pchar(Result);
+  P:=Pchar(pointer(Result));
   for i := 1 to Length(Result) do
     begin
     if (P^ in ['A'..'Z']) then P^ := char(byte(p^) + 32);
@@ -418,7 +420,7 @@ function AnsiLastChar(const S: string): PChar;
 
 begin
   //!! No multibyte yet, so we return the last one.
-  result:=StrEnd(Pchar(S));
+  result:=StrEnd(Pchar(pointer(S)));  // strend checks for nil
   Dec(Result);
 end ;
 
@@ -970,8 +972,8 @@ end;
 
 Function StrToFloat(Const S : String; Const FormatSettings: TFormatSettings) : Extended;
 
-Begin
-  If Not TextToFloat(Pchar(S),Result,FormatSettings) then
+Begin // texttofloat handles NIL properly
+  If Not TextToFloat(Pchar(pointer(S)),Result,FormatSettings) then
     Raise EConvertError.createfmt(SInValidFLoat,[S]);
 End;
 
@@ -984,7 +986,7 @@ end;
 Function StrToFloatDef(Const S: String; Const Default: Extended; Const FormatSettings: TFormatSettings): Extended;
 
 begin
-   if not TextToFloat(PChar(S),Result,fvExtended,FormatSettings) then
+   if not TextToFloat(PChar(pointer(S)),Result,fvExtended,FormatSettings) then
      Result:=Default;
 end;
 
@@ -1068,7 +1070,7 @@ end;
 
 Function TryStrToFloat(Const S : String; Var Value: Single; Const FormatSettings: TFormatSettings): Boolean;
 Begin
-  Result := TextToFloat(PChar(S), Value, fvSingle,FormatSettings);
+  Result := TextToFloat(PChar(pointer(S)), Value, fvSingle,FormatSettings);
 End;
 
 Function TryStrToFloat(Const S : String; Var Value: Double): Boolean;
@@ -1079,7 +1081,7 @@ end;
 
 Function TryStrToFloat(Const S : String; Var Value: Double; Const FormatSettings: TFormatSettings): Boolean;
 Begin
-  Result := TextToFloat(PChar(S), Value, fvDouble,FormatSettings);
+  Result := TextToFloat(PChar(pointer(S)), Value, fvDouble,FormatSettings);
 End;
 
 {$ifdef FPC_HAS_TYPE_EXTENDED}
@@ -1091,7 +1093,7 @@ end;
 
 Function TryStrToFloat(Const S : String; Var Value: Extended; Const FormatSettings: TFormatSettings): Boolean;
 Begin
-  Result := TextToFloat(PChar(S), Value,FormatSettings);
+  Result := TextToFloat(PChar(pointer(S)), Value,FormatSettings);
 End;
 {$endif FPC_HAS_TYPE_EXTENDED}
 
@@ -1617,7 +1619,7 @@ function AnsiDequotedStr(const S: string; AQuote: Char): string;
 var p : pchar;
 
 begin
-  p:=pchar(s); // work around CONST
+  p:=pchar(pointer(s)); // work around CONST. Ansiextract is safe for nil
   result:=AnsiExtractquotedStr(p,AQuote);
   if result='' Then
     result:=s;
@@ -1625,20 +1627,20 @@ end;
 
 function StrToCurr(const S: string): Currency;
 begin
-  if not TextToFloat(PChar(S), Result, fvCurrency) then
+  if not TextToFloat(PChar(pointer(S)), Result, fvCurrency) then
     Raise EConvertError.createfmt(SInValidFLoat,[S]);
 end;
 
 
 Function TryStrToCurr(Const S : String; Var Value: Currency): Boolean;
 Begin
-  Result := TextToFloat(PChar(S), Value, fvCurrency);
+  Result := TextToFloat(PChar(pointer(S)), Value, fvCurrency);
 End;
 
 
 function StrToCurrDef(const S: string; Default : Currency): Currency;
 begin
-  if not TextToFloat(PChar(S), Result, fvCurrency) then
+  if not TextToFloat(PChar(pointer(S)), Result, fvCurrency) then
     Result:=Default;
 end;
 
@@ -2318,7 +2320,7 @@ Function FormatFloat(Const Format : String; Value : Extended; Const FormatSettin
 Var
   buf : Array[0..1024] of char;
 
-Begin
+Begin // not changed to pchar(pointer(). Possibly not safe
   Buf[FloatToTextFmt(@Buf[0],Value,Pchar(Format),FormatSettings)]:=#0;
   Result:=StrPas(@Buf[0]);
 End;

+ 17 - 17
rtl/unix/sysutils.pp

@@ -186,7 +186,7 @@ BEGIN
     1 : LinuxFlags:=LinuxFlags or O_WrOnly;
     2 : LinuxFlags:=LinuxFlags or O_RdWr;
   end;
-  FileOpen:=fpOpen (FileName,LinuxFlags);
+  FileOpen:=fpOpen (pointer(FileName),LinuxFlags);
   //!! We need to set locking based on Mode !!
 end;
 
@@ -194,14 +194,14 @@ end;
 Function FileCreate (Const FileName : String) : Longint;
 
 begin
-  FileCreate:=fpOpen(FileName,O_RdWr or O_Creat or O_Trunc);
+  FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc);
 end;
 
 
 Function FileCreate (Const FileName : String;Mode : Longint) : Longint;
 
 BEGIN
-  FileCreate:=fpOpen(FileName,O_RdWr or O_Creat or O_Trunc,Mode);
+  FileCreate:=fpOpen(pointer(FileName),O_RdWr or O_Creat or O_Trunc,Mode);
 end;
 
 
@@ -264,7 +264,7 @@ Function FileAge (Const FileName : String): Longint;
 Var Info : Stat;
 
 begin
-  If  fpstat (FileName,Info)<0 then
+  If  fpstat (pointer(FileName),Info)<0 then
     exit(-1)
   else
     Result:=UnixToWinAge(info.st_mtime);
@@ -276,7 +276,7 @@ Function FileExists (Const FileName : String) : Boolean;
 begin
   // Don't use stat. It fails on files >2 GB.
   // Access obeys the same access rules, so the result should be the same.
-  FileExists:=fpAccess(filename,F_OK)=0;
+  FileExists:=fpAccess(pointer(filename),F_OK)=0;
 end;
 
 
@@ -285,7 +285,7 @@ Function DirectoryExists (Const Directory : String) : Boolean;
 Var Info : Stat;
 
 begin
-  DirectoryExists:=(fpstat(Directory,Info)>=0) and fpS_ISDIR(Info.st_mode);
+  DirectoryExists:=(fpstat(pointer(Directory),Info)>=0) and fpS_ISDIR(Info.st_mode);
 end;
 
 
@@ -423,9 +423,9 @@ var
   WinAttr : longint;
 begin
   FindGetFileInfo:=false;
-  if not fpstat(s,st)>=0 then
+  if not fpstat(pointer(s),st)>=0 then
    exit;
-  WinAttr:=LinuxToWinAttr(PChar(s),st);
+  WinAttr:=LinuxToWinAttr(PChar(pointer(s)),st);
   If (f.FindHandle = nil) or ((WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0) Then
    Begin
      f.Name:=ExtractFileName(s);
@@ -464,7 +464,7 @@ Begin
         DirName:='./'
       Else
         DirName:=Copy(UnixFindData^.SearchSpec,1,UnixFindData^.NamePos);
-      UnixFindData^.DirPtr := fpopendir(Pchar(DirName));
+      UnixFindData^.DirPtr := fpopendir(Pchar(pointer(DirName)));
     end;
   SName:=Copy(UnixFindData^.SearchSpec,UnixFindData^.NamePos+1,Length(UnixFindData^.SearchSpec));
   Found:=False;
@@ -554,7 +554,7 @@ Function FileGetAttr (Const FileName : String) : Longint;
 Var Info : Stat;
 
 begin
-  If  FpStat (FileName,Info)<0 then
+  If  FpStat (pointer(FileName),Info)<0 then
     Result:=-1
   Else
     Result:=LinuxToWinAttr(Pchar(ExtractFileName(FileName)),Info);
@@ -571,20 +571,20 @@ end;
 Function DeleteFile (Const FileName : String) : Boolean;
 
 begin
-  Result:=fpUnLink (FileName)>=0;
+  Result:=fpUnLink (pointer(FileName))>=0;
 end;
 
 
 Function RenameFile (Const OldName, NewName : String) : Boolean;
 
 begin
-  RenameFile:=BaseUnix.FpRename(OldNAme,NewName)>=0;
+  RenameFile:=BaseUnix.FpRename(pointer(OldNAme),pointer(NewName))>=0;
 end;
 
 Function FileIsReadOnly(const FileName: String): Boolean;
 
 begin
-  Result := fpAccess(PChar(FileName),W_OK)<>0;
+  Result := fpAccess(PChar(pointer(FileName)),W_OK)<>0;
 end;
 
 Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
@@ -596,7 +596,7 @@ begin
   Result := 0;
   t.actime := Age;
   t.modtime := Age;
-  if fputime(PChar(FileName), @t) = -1 then
+  if fputime(PChar(pointer(FileName)), @t) = -1 then
     Result := fpgeterrno;
 end;
 
@@ -830,7 +830,7 @@ end;
 Function GetEnvironmentVariable(Const EnvVar : String) : String;
 
 begin
-  Result:=StrPas(BaseUnix.FPGetenv(PChar(EnvVar)));
+  Result:=StrPas(BaseUnix.FPGetenv(PChar(pointer(EnvVar))));
 end;
 
 Function GetEnvironmentVariableCount : Integer;
@@ -868,7 +868,7 @@ Begin
          string }
        UniqueString(CommandLine);
        cmdline2:=StringtoPPChar(CommandLine,1);
-       cmdline2^:=pchar(Path);
+       cmdline2^:=pchar(pointer(Path));
      end
    else
      begin
@@ -893,7 +893,7 @@ Begin
    begin
    {The child does the actual exec, and then exits}
     {$ifdef FPC_USE_FPEXEC}
-      fpexecv(pchar(Path),Cmdline2);
+      fpexecv(pchar(pointer(Path)),Cmdline2);
     {$else}
       Execl(CommandLine);
     {$endif}