mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 19:49:22 +02:00
* pchar(pointer()) isms that were safe.
git-svn-id: trunk@8672 -
This commit is contained in:
parent
faa8383403
commit
827d380691
@ -534,7 +534,7 @@ var
|
|||||||
var Len: integer;
|
var Len: integer;
|
||||||
begin
|
begin
|
||||||
Len := Length(Str);
|
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);
|
StrMove(ResultCurrent, pchar(Str), Len);
|
||||||
ResultCurrent := ResultCurrent + Len;
|
ResultCurrent := ResultCurrent + Len;
|
||||||
ResultLen := ResultLen + Len;
|
ResultLen := ResultLen + Len;
|
||||||
@ -578,7 +578,7 @@ var
|
|||||||
tmp:integer;
|
tmp:integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
FormatCurrent := Pchar(FormatStr);
|
FormatCurrent := Pchar(pointer(FormatStr));
|
||||||
FormatEnd := FormatCurrent + Length(FormatStr);
|
FormatEnd := FormatCurrent + Length(FormatStr);
|
||||||
Clock12 := false;
|
Clock12 := false;
|
||||||
P := FormatCurrent;
|
P := FormatCurrent;
|
||||||
|
@ -72,8 +72,9 @@ Var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result := S;
|
Result := S;
|
||||||
|
if not assigned(pointer(result)) then exit;
|
||||||
UniqueString(Result);
|
UniqueString(Result);
|
||||||
P:=Pchar(Result);
|
P:=Pchar(pointer(Result));
|
||||||
for i := 1 to Length(Result) do
|
for i := 1 to Length(Result) do
|
||||||
begin
|
begin
|
||||||
if (P^ in ['a'..'z']) then P^ := char(byte(p^) - 32);
|
if (P^ in ['a'..'z']) then P^ := char(byte(p^) - 32);
|
||||||
@ -92,8 +93,9 @@ Var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result := S;
|
Result := S;
|
||||||
|
if not assigned(pointer(result)) then exit;
|
||||||
UniqueString(Result);
|
UniqueString(Result);
|
||||||
P:=Pchar(Result);
|
P:=Pchar(pointer(Result));
|
||||||
for i := 1 to Length(Result) do
|
for i := 1 to Length(Result) do
|
||||||
begin
|
begin
|
||||||
if (P^ in ['A'..'Z']) then P^ := char(byte(p^) + 32);
|
if (P^ in ['A'..'Z']) then P^ := char(byte(p^) + 32);
|
||||||
@ -418,7 +420,7 @@ function AnsiLastChar(const S: string): PChar;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
//!! No multibyte yet, so we return the last one.
|
//!! No multibyte yet, so we return the last one.
|
||||||
result:=StrEnd(Pchar(S));
|
result:=StrEnd(Pchar(pointer(S))); // strend checks for nil
|
||||||
Dec(Result);
|
Dec(Result);
|
||||||
end ;
|
end ;
|
||||||
|
|
||||||
@ -970,8 +972,8 @@ end;
|
|||||||
|
|
||||||
Function StrToFloat(Const S : String; Const FormatSettings: TFormatSettings) : Extended;
|
Function StrToFloat(Const S : String; Const FormatSettings: TFormatSettings) : Extended;
|
||||||
|
|
||||||
Begin
|
Begin // texttofloat handles NIL properly
|
||||||
If Not TextToFloat(Pchar(S),Result,FormatSettings) then
|
If Not TextToFloat(Pchar(pointer(S)),Result,FormatSettings) then
|
||||||
Raise EConvertError.createfmt(SInValidFLoat,[S]);
|
Raise EConvertError.createfmt(SInValidFLoat,[S]);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
@ -984,7 +986,7 @@ end;
|
|||||||
Function StrToFloatDef(Const S: String; Const Default: Extended; Const FormatSettings: TFormatSettings): Extended;
|
Function StrToFloatDef(Const S: String; Const Default: Extended; Const FormatSettings: TFormatSettings): Extended;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if not TextToFloat(PChar(S),Result,fvExtended,FormatSettings) then
|
if not TextToFloat(PChar(pointer(S)),Result,fvExtended,FormatSettings) then
|
||||||
Result:=Default;
|
Result:=Default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1068,7 +1070,7 @@ end;
|
|||||||
|
|
||||||
Function TryStrToFloat(Const S : String; Var Value: Single; Const FormatSettings: TFormatSettings): Boolean;
|
Function TryStrToFloat(Const S : String; Var Value: Single; Const FormatSettings: TFormatSettings): Boolean;
|
||||||
Begin
|
Begin
|
||||||
Result := TextToFloat(PChar(S), Value, fvSingle,FormatSettings);
|
Result := TextToFloat(PChar(pointer(S)), Value, fvSingle,FormatSettings);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function TryStrToFloat(Const S : String; Var Value: Double): Boolean;
|
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;
|
Function TryStrToFloat(Const S : String; Var Value: Double; Const FormatSettings: TFormatSettings): Boolean;
|
||||||
Begin
|
Begin
|
||||||
Result := TextToFloat(PChar(S), Value, fvDouble,FormatSettings);
|
Result := TextToFloat(PChar(pointer(S)), Value, fvDouble,FormatSettings);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||||
@ -1091,7 +1093,7 @@ end;
|
|||||||
|
|
||||||
Function TryStrToFloat(Const S : String; Var Value: Extended; Const FormatSettings: TFormatSettings): Boolean;
|
Function TryStrToFloat(Const S : String; Var Value: Extended; Const FormatSettings: TFormatSettings): Boolean;
|
||||||
Begin
|
Begin
|
||||||
Result := TextToFloat(PChar(S), Value,FormatSettings);
|
Result := TextToFloat(PChar(pointer(S)), Value,FormatSettings);
|
||||||
End;
|
End;
|
||||||
{$endif FPC_HAS_TYPE_EXTENDED}
|
{$endif FPC_HAS_TYPE_EXTENDED}
|
||||||
|
|
||||||
@ -1617,7 +1619,7 @@ function AnsiDequotedStr(const S: string; AQuote: Char): string;
|
|||||||
var p : pchar;
|
var p : pchar;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
p:=pchar(s); // work around CONST
|
p:=pchar(pointer(s)); // work around CONST. Ansiextract is safe for nil
|
||||||
result:=AnsiExtractquotedStr(p,AQuote);
|
result:=AnsiExtractquotedStr(p,AQuote);
|
||||||
if result='' Then
|
if result='' Then
|
||||||
result:=s;
|
result:=s;
|
||||||
@ -1625,20 +1627,20 @@ end;
|
|||||||
|
|
||||||
function StrToCurr(const S: string): Currency;
|
function StrToCurr(const S: string): Currency;
|
||||||
begin
|
begin
|
||||||
if not TextToFloat(PChar(S), Result, fvCurrency) then
|
if not TextToFloat(PChar(pointer(S)), Result, fvCurrency) then
|
||||||
Raise EConvertError.createfmt(SInValidFLoat,[S]);
|
Raise EConvertError.createfmt(SInValidFLoat,[S]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function TryStrToCurr(Const S : String; Var Value: Currency): Boolean;
|
Function TryStrToCurr(Const S : String; Var Value: Currency): Boolean;
|
||||||
Begin
|
Begin
|
||||||
Result := TextToFloat(PChar(S), Value, fvCurrency);
|
Result := TextToFloat(PChar(pointer(S)), Value, fvCurrency);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
function StrToCurrDef(const S: string; Default : Currency): Currency;
|
function StrToCurrDef(const S: string; Default : Currency): Currency;
|
||||||
begin
|
begin
|
||||||
if not TextToFloat(PChar(S), Result, fvCurrency) then
|
if not TextToFloat(PChar(pointer(S)), Result, fvCurrency) then
|
||||||
Result:=Default;
|
Result:=Default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2318,7 +2320,7 @@ Function FormatFloat(Const Format : String; Value : Extended; Const FormatSettin
|
|||||||
Var
|
Var
|
||||||
buf : Array[0..1024] of char;
|
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;
|
Buf[FloatToTextFmt(@Buf[0],Value,Pchar(Format),FormatSettings)]:=#0;
|
||||||
Result:=StrPas(@Buf[0]);
|
Result:=StrPas(@Buf[0]);
|
||||||
End;
|
End;
|
||||||
|
@ -186,7 +186,7 @@ BEGIN
|
|||||||
1 : LinuxFlags:=LinuxFlags or O_WrOnly;
|
1 : LinuxFlags:=LinuxFlags or O_WrOnly;
|
||||||
2 : LinuxFlags:=LinuxFlags or O_RdWr;
|
2 : LinuxFlags:=LinuxFlags or O_RdWr;
|
||||||
end;
|
end;
|
||||||
FileOpen:=fpOpen (FileName,LinuxFlags);
|
FileOpen:=fpOpen (pointer(FileName),LinuxFlags);
|
||||||
//!! We need to set locking based on Mode !!
|
//!! We need to set locking based on Mode !!
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -194,14 +194,14 @@ end;
|
|||||||
Function FileCreate (Const FileName : String) : Longint;
|
Function FileCreate (Const FileName : String) : Longint;
|
||||||
|
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function FileCreate (Const FileName : String;Mode : Longint) : Longint;
|
Function FileCreate (Const FileName : String;Mode : Longint) : Longint;
|
||||||
|
|
||||||
BEGIN
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ Function FileAge (Const FileName : String): Longint;
|
|||||||
Var Info : Stat;
|
Var Info : Stat;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
If fpstat (FileName,Info)<0 then
|
If fpstat (pointer(FileName),Info)<0 then
|
||||||
exit(-1)
|
exit(-1)
|
||||||
else
|
else
|
||||||
Result:=UnixToWinAge(info.st_mtime);
|
Result:=UnixToWinAge(info.st_mtime);
|
||||||
@ -276,7 +276,7 @@ Function FileExists (Const FileName : String) : Boolean;
|
|||||||
begin
|
begin
|
||||||
// Don't use stat. It fails on files >2 GB.
|
// Don't use stat. It fails on files >2 GB.
|
||||||
// Access obeys the same access rules, so the result should be the same.
|
// 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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ Function DirectoryExists (Const Directory : String) : Boolean;
|
|||||||
Var Info : Stat;
|
Var Info : Stat;
|
||||||
|
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -423,9 +423,9 @@ var
|
|||||||
WinAttr : longint;
|
WinAttr : longint;
|
||||||
begin
|
begin
|
||||||
FindGetFileInfo:=false;
|
FindGetFileInfo:=false;
|
||||||
if not fpstat(s,st)>=0 then
|
if not fpstat(pointer(s),st)>=0 then
|
||||||
exit;
|
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
|
If (f.FindHandle = nil) or ((WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0) Then
|
||||||
Begin
|
Begin
|
||||||
f.Name:=ExtractFileName(s);
|
f.Name:=ExtractFileName(s);
|
||||||
@ -464,7 +464,7 @@ Begin
|
|||||||
DirName:='./'
|
DirName:='./'
|
||||||
Else
|
Else
|
||||||
DirName:=Copy(UnixFindData^.SearchSpec,1,UnixFindData^.NamePos);
|
DirName:=Copy(UnixFindData^.SearchSpec,1,UnixFindData^.NamePos);
|
||||||
UnixFindData^.DirPtr := fpopendir(Pchar(DirName));
|
UnixFindData^.DirPtr := fpopendir(Pchar(pointer(DirName)));
|
||||||
end;
|
end;
|
||||||
SName:=Copy(UnixFindData^.SearchSpec,UnixFindData^.NamePos+1,Length(UnixFindData^.SearchSpec));
|
SName:=Copy(UnixFindData^.SearchSpec,UnixFindData^.NamePos+1,Length(UnixFindData^.SearchSpec));
|
||||||
Found:=False;
|
Found:=False;
|
||||||
@ -554,7 +554,7 @@ Function FileGetAttr (Const FileName : String) : Longint;
|
|||||||
Var Info : Stat;
|
Var Info : Stat;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
If FpStat (FileName,Info)<0 then
|
If FpStat (pointer(FileName),Info)<0 then
|
||||||
Result:=-1
|
Result:=-1
|
||||||
Else
|
Else
|
||||||
Result:=LinuxToWinAttr(Pchar(ExtractFileName(FileName)),Info);
|
Result:=LinuxToWinAttr(Pchar(ExtractFileName(FileName)),Info);
|
||||||
@ -571,20 +571,20 @@ end;
|
|||||||
Function DeleteFile (Const FileName : String) : Boolean;
|
Function DeleteFile (Const FileName : String) : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=fpUnLink (FileName)>=0;
|
Result:=fpUnLink (pointer(FileName))>=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
RenameFile:=BaseUnix.FpRename(OldNAme,NewName)>=0;
|
RenameFile:=BaseUnix.FpRename(pointer(OldNAme),pointer(NewName))>=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function FileIsReadOnly(const FileName: String): Boolean;
|
Function FileIsReadOnly(const FileName: String): Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result := fpAccess(PChar(FileName),W_OK)<>0;
|
Result := fpAccess(PChar(pointer(FileName)),W_OK)<>0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
|
Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
|
||||||
@ -596,7 +596,7 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
t.actime := Age;
|
t.actime := Age;
|
||||||
t.modtime := Age;
|
t.modtime := Age;
|
||||||
if fputime(PChar(FileName), @t) = -1 then
|
if fputime(PChar(pointer(FileName)), @t) = -1 then
|
||||||
Result := fpgeterrno;
|
Result := fpgeterrno;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -830,7 +830,7 @@ end;
|
|||||||
Function GetEnvironmentVariable(Const EnvVar : String) : String;
|
Function GetEnvironmentVariable(Const EnvVar : String) : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=StrPas(BaseUnix.FPGetenv(PChar(EnvVar)));
|
Result:=StrPas(BaseUnix.FPGetenv(PChar(pointer(EnvVar))));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function GetEnvironmentVariableCount : Integer;
|
Function GetEnvironmentVariableCount : Integer;
|
||||||
@ -868,7 +868,7 @@ Begin
|
|||||||
string }
|
string }
|
||||||
UniqueString(CommandLine);
|
UniqueString(CommandLine);
|
||||||
cmdline2:=StringtoPPChar(CommandLine,1);
|
cmdline2:=StringtoPPChar(CommandLine,1);
|
||||||
cmdline2^:=pchar(Path);
|
cmdline2^:=pchar(pointer(Path));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -893,7 +893,7 @@ Begin
|
|||||||
begin
|
begin
|
||||||
{The child does the actual exec, and then exits}
|
{The child does the actual exec, and then exits}
|
||||||
{$ifdef FPC_USE_FPEXEC}
|
{$ifdef FPC_USE_FPEXEC}
|
||||||
fpexecv(pchar(Path),Cmdline2);
|
fpexecv(pchar(pointer(Path)),Cmdline2);
|
||||||
{$else}
|
{$else}
|
||||||
Execl(CommandLine);
|
Execl(CommandLine);
|
||||||
{$endif}
|
{$endif}
|
||||||
|
Loading…
Reference in New Issue
Block a user