Skip to content

Commit

Permalink
Fixed FPC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
maximmasiutin committed Mar 14, 2023
1 parent 4aff3ee commit 6afaf7f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
36 changes: 31 additions & 5 deletions SRC/SrvMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ function StrToFileTime(AStr: AnsiString): DWORD;
Result := INVALID_FILE_TIME;
Clear(d, SizeOf(d));
s := AStr;
z := '';
GetWrd(s, z, ' ');
GetWrdD(s, z);
v := Vl(z);
Expand Down Expand Up @@ -698,6 +699,7 @@ procedure TPipeWriteStdThread.Execute;
slen: Integer;
begin
slen := Length(s);
j := 0;
if slen > 0 then
WriteFile(HPipe, s[1], slen, j, nil);
end;
Expand All @@ -724,6 +726,7 @@ function DoCollect(Collector: TCollector; EntityHeader: TEntityHeader;
end
else
begin
z := '';
GetWrdStrictUC(s, z);
Delete(z, Length(z), 1);
if not EntityHeader.Filter(z, s) then
Expand All @@ -742,6 +745,8 @@ procedure TPipeReadErrThread.Execute;
j: DWORD;
begin
repeat
j := 0;
FillChar(ss, SizeOf(ss), 0);
if (not ReadFile(HPipe, ss[1], 250, j, nil)) or (j = 0) then
Break;
ss[0] := AnsiChar(j);
Expand All @@ -754,6 +759,7 @@ procedure TPipeReadStdThread.Execute;
j: DWORD;
begin
repeat
j := 0;
if (not ReadFile(HPipe, Buffer^, CHTTPServerThreadBufSize, j, nil)) or
(j = 0) then
Break;
Expand Down Expand Up @@ -786,6 +792,9 @@ function ExecuteScript(const AExecutable, APath, AScript, AQueryParam, AEnvStr,
var
d, n, e: AnsiString;
begin
d := '';
n := '';
e := '';
FSPlit(AExecutable, d, n, e);
Result := n + e + ' is a GUI application';
end;
Expand Down Expand Up @@ -925,6 +934,7 @@ function ExecuteScript(const AExecutable, APath, AScript, AQueryParam, AEnvStr,

while not PipeReadStdThread.Error do
begin
Actually := 0;
if (not ReadFile(so_r, Buffer, CHTTPServerThreadBufSize, Actually, nil)) or
(Actually = 0) then
Break;
Expand Down Expand Up @@ -965,6 +975,7 @@ procedure AddAgentLog(const AAgent: AnsiString);
s := AAgent + #13#10;
EnterCriticalSection(CSAgentLog);
slen := Length(s);
b := 0;
WriteFile(HAgentLog, s[1], slen, b, nil);
LeaveCriticalSection(CSAgentLog);
end;
Expand All @@ -980,6 +991,7 @@ procedure AddRefererLog(const ARefererSrc, ARefererDst: AnsiString);
s := ARefererSrc + ' -> ' + ARefererDst + #13#10;
EnterCriticalSection(CSRefererLog);
slen := Length(s);
b := 0;
WriteFile(HRefererLog, s[1], slen, b, nil);
LeaveCriticalSection(CSRefererLog);
end;
Expand All @@ -990,6 +1002,8 @@ function CurTime: AnsiString;
b: Integer;
s: AnsiString;
begin
s := '';
FillChar(lt, SizeOf(lt), 0);
GetLocalTime(lt);
b := TimeZoneBias;
if b < 0 then
Expand Down Expand Up @@ -1037,6 +1051,7 @@ procedure AddAccessLog(const ARemoteHost, ARequestLine, AHTTPVersion,
#13#10;
EnterCriticalSection(CSAccessLog);
slen := Length(z);
b := 0;
WriteFile(HAccessLog, z[1], slen, b, nil);
LeaveCriticalSection(CSAccessLog);
end;
Expand All @@ -1050,6 +1065,7 @@ procedure AddErrorLog(const AErr: AnsiString);
s := CurTime + ' ' + AErr + #13#10;
EnterCriticalSection(CSErrorLog);
slen := Length(s);
b := 0;
WriteFile(HErrorLog, s[1], slen, b, nil);
LeaveCriticalSection(CSErrorLog);
end;
Expand Down Expand Up @@ -1124,6 +1140,7 @@ function OpenRequestedFile(const AFName: AnsiString; thr: THTTPServerThread;
z := LowerCase(CopyLeft(ExtractFileExt(AFName), 2));
if z <> '' then
begin
i := -1;
if not ContentTypes.Search(@z, i) then
z := ''
else
Expand Down Expand Up @@ -1251,6 +1268,7 @@ function FindExecutableCached(const LocalFName, sPath: AnsiString;
Exit;
end;
ExecutableCache.Enter;
i := -1;
if ExecutableCache.Search(@LocalFName, i) then
begin
p := ExecutableCache[i];
Expand Down Expand Up @@ -1314,6 +1332,7 @@ function FindRootFileEx(const AURI: AnsiString; var IsCGI: Boolean): AnsiString;
s := GetEnvVariable('PATHEXT');
while s <> '' do
begin
z := '';
GetWrd(s, z, ';');
if Length(z) < 2 then
Continue;
Expand All @@ -1337,6 +1356,7 @@ function FindRootFile(const AURI: AnsiString; var IsCGI: Boolean): AnsiString;
p: Pointer;
begin
RootCacheColl.Enter;
i := -1;
Found := RootCacheColl.Search(@AURI, i);
if Found then
begin
Expand Down Expand Up @@ -1513,6 +1533,7 @@ function WebServerHttpResponse(thr: THTTPServerThread; d: THTTPData)
PathInfo := CopyLeft(LocalFName, Length(CgiFile) + 2);
ts := PathInfo;
repeat
z := '';
GetWrd(ts, z, '\');
CgiFile := CgiFile + '\' + z;
fa := GetFileAttributesA(@(CgiFile[1]));
Expand Down Expand Up @@ -1664,6 +1685,7 @@ function WebServerHttpResponse(thr: THTTPServerThread; d: THTTPData)

if CheckedURI[Length(CheckedURI)] = '\' then
begin
IsCGI := False;
LocalFName := FindRootFile(CheckedURI, IsCGI);
if IsCGI then
begin
Expand Down Expand Up @@ -1788,6 +1810,7 @@ procedure THTTPServerThread.Execute;

// Parse HTTP version
s := HTTPVersion;
z := '';
GetWrd(s, z, '/');
if z <> 'HTTP' then
Break;
Expand Down Expand Up @@ -2319,9 +2342,9 @@ procedure THTTPServerThread.Execute;

{ Allocate an object instance }

function CalcJmpOffset(Src, Dest: Pointer): Longint;
function CalcJmpOffset(Src, Dest: Pointer): NativeInt;
begin
Result := Longint(Dest) - (Longint(Src) + 5);
Result := NativeInt(Dest) - (NativeInt(Src) + 5);
end;

function MakeObjectInstance(Method: TWndMethod): Pointer;
Expand All @@ -2345,8 +2368,8 @@ procedure THTTPServerThread.Execute;
Instance^.Offset := CalcJmpOffset(Instance, @Block^.Code);
Instance^.Next := InstFreeList;
InstFreeList := Instance;
Inc(Longint(Instance), SizeOf(TObjectInstance));
until Longint(Instance) - Longint(Block) >= SizeOf(TInstanceBlock);
Inc(NativeInt(Instance), SizeOf(TObjectInstance));
until NativeInt(Instance) - NativeInt(Block) >= SizeOf(TInstanceBlock);
InstBlockList := Block;
end;
Result := InstFreeList;
Expand Down Expand Up @@ -2378,6 +2401,7 @@ procedure THTTPServerThread.Execute;
begin
UtilWindowClass.hInstance := hInstance;
UtilWindowClass.lpfnWndProc := @DefWindowProc;
FillChar(TempClass, SizeOf(TempClass), 0);
ClassRegistered := GetClassInfo(hInstance, UtilWindowClass.lpszClassName,
TempClass);
if not ClassRegistered or ({$IFDEF FPC_DELPHI}@{$ENDIF}TempClass.lpfnWndProc
Expand All @@ -2390,7 +2414,7 @@ procedure THTTPServerThread.Execute;
Result := CreateWindowEx(WS_EX_TOOLWINDOW, UtilWindowClass.lpszClassName,
'', WS_POPUP { !0 } , 0, 0, 0, 0, 0, 0, hInstance, nil);
if Assigned(Method) then
SetWindowLong(Result, GWL_WNDPROC, Longint(MakeObjectInstance(Method)));
SetWindowLong(Result, GWL_WNDPROC, LONG(MakeObjectInstance(Method)));
end;

procedure DeallocateHWnd(Wnd: HWND);
Expand Down Expand Up @@ -2446,6 +2470,7 @@ TMainThread = class(TThread)
s: AnsiString;
begin
Leave := False;
FillChar(WData, SizeOf(WData), 0);
err := WSAStartup(MakeWord(1, 1), WData);
if err <> 0 then
begin
Expand Down Expand Up @@ -2531,6 +2556,7 @@ TMainThread = class(TThread)
WP := TWndProc.Create;
WP.Handle := AllocateHWnd({$IFDEF FPC_OBJFPC}@{$ENDIF}WP.WndProc);
repeat
FillChar(M, SizeOf(M), 0);
GetMessage(M, 0, 0, 0);
if M.Message = WM_QUIT then
begin
Expand Down
25 changes: 23 additions & 2 deletions SRC/xBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ function uFindFirst(const FName: AnsiString; var FindData: TuFindData): THandle;
end
else
begin
FillChar(wf, SizeOf(wf), 0);
Result := FindFirstFileA(@(FName[1]), wf);
if Result <> INVALID_HANDLE_VALUE then
CvtFD(wf, FindData);
Expand All @@ -662,6 +663,7 @@ function uFindNext(Handle: THandle; var FindData: TuFindData): Boolean;
var
wf: TWin32FindDataA;
begin
FillChar(wf, SizeOf(wf), 0);
Result := FindNextFileA(Handle, wf);
if Result then
CvtFD(wf, FindData);
Expand Down Expand Up @@ -707,13 +709,15 @@ function BothKVC(const S: AnsiString): Boolean;

function AddRightSpaces(const S: AnsiString; NumSpaces: Integer): AnsiString;
begin
Result := '';
SetLength(Result, NumSpaces);
FillChar(Result[1], NumSpaces, ' ');
Move(S[1], Result[1], MinI(NumSpaces, Length(S)));
end;

function Hex2(a: Byte): AnsiString;
begin
Result := '';
SetLength(Result, 2);
Result[1] := rrLoHexChar[a shr 4];
Result[2] := rrLoHexChar[a and $F];
Expand All @@ -723,6 +727,7 @@ function Hex4(a: Word): AnsiString;
var
I: Integer;
begin
Result := '';
SetLength(Result, 4);
for I := 0 to 3 do
begin
Expand All @@ -735,6 +740,7 @@ function Hex8(a: DWORD): AnsiString;
var
I: DWORD;
begin
Result := '';
SetLength(Result, 8);
for I := 0 to 7 do
begin
Expand Down Expand Up @@ -1495,6 +1501,7 @@ function _GetFileSize(const FName: AnsiString): DWORD;

function WindowsDirectory: AnsiString;
begin
Result := '';
SetLength(Result, MAX_PATH);
GetWindowsDirectoryA(@(Result[1]), MAX_PATH);
SetLength(Result, NulSearch(Result[1]));
Expand Down Expand Up @@ -1570,6 +1577,7 @@ function ReadRegString(Key: DWORD; const AStrName: AnsiString): AnsiString;
PDataBuf: PAnsiChar;
begin
L := 250;
z := '';
SetLength(z, L + 1);
PDataBuf := @(z[1]);
T := REG_SZ;
Expand Down Expand Up @@ -1940,6 +1948,7 @@ function TSortedColl.IndexOf(Item: Pointer): Integer;
I: Integer;
begin
IndexOf := -1;
I := -1;
if Search(KeyOf(Item), I) then
begin
if Duplicates then
Expand All @@ -1954,6 +1963,7 @@ procedure TSortedColl.Insert(Item: Pointer);
var
I: Integer;
begin
I := -1;
if not Search(KeyOf(Item), I) or Duplicates then
AtInsert(I, Item);
end;
Expand Down Expand Up @@ -2036,6 +2046,7 @@ procedure TStringColl.FillEnum(Str: AnsiString; Delim: AnsiChar;
begin
while Str <> '' do
begin
z := '';
GetWrd(Str, z, Delim);
if Sorted then
Ins(z)
Expand All @@ -2048,6 +2059,7 @@ function TStringColl.Found(const Str: AnsiString): Boolean;
var
I: Integer;
begin
I := -1;
Result := Search(@Str, I);
end;

Expand Down Expand Up @@ -2307,6 +2319,7 @@ function TempFileName(const APath, APfx: AnsiString): AnsiString;
Result := '';
Exit;
end;
S := '';
SetLength(S, 1000);
GetTempFileNameA(@(APath[1]), @(APfx[1]), 0, @(S[1]));
Result := Copy(S, 1, NulSearch(S[1]));
Expand Down Expand Up @@ -2502,6 +2515,8 @@ function ExpandFileName(const FileName: AnsiString): AnsiString;
end
else
begin
FillChar(Buffer, SizeOf(Buffer), 0);
FName := nil;
SetString(Result, Buffer, GetFullPathNameA(@(FileName[1]), SizeOf(Buffer),
Buffer, FName));
end;
Expand Down Expand Up @@ -2851,6 +2866,7 @@ function UnpackXchars(var S: AnsiString; P: Boolean): Boolean;

begin
Result := False;
R := '';
sl := Length(S);
I := 0;
while I < sl do
Expand Down Expand Up @@ -2903,6 +2919,7 @@ function ProcessQuotes(var S: AnsiString): Boolean;
c: AnsiChar;
begin
Result := False;
R := '';
KVC := False;
for I := 1 to Length(S) do
begin
Expand Down Expand Up @@ -2948,6 +2965,7 @@ function _Val(const S: AnsiString; var V: Integer): Boolean;

function StoI(const S: AnsiString): Integer;
begin
Result := 0;
if not _Val(S, Result) then
Result := 0;
end;
Expand Down Expand Up @@ -2989,8 +3007,10 @@ procedure GetBias;
T, L: TFileTime;
a, B, c: DWORD;
begin
FillChar(T, SizeOf(T), 0);
FillChar(L, SizeOf(L), 0);
GetSystemTimeAsFileTime(T);
FileTimeToLocalFileTime(T, L);
if not FileTimeToLocalFileTime(T, L) then Exit;
a := uCvtGetFileTime(T.dwLowDateTime, T.dwHighDateTime);
B := uCvtGetFileTime(L.dwLowDateTime, L.dwHighDateTime);
if a > B then
Expand Down Expand Up @@ -3022,7 +3042,7 @@ THostCacheColl = class(TSortedColl)

function THostCacheColl.Compare(Key1, Key2: Pointer): Integer;
begin
Result := Integer(Key1) - Integer(Key2);
Result := NativeInt(Key1) - NativeInt(Key2);
end;

function THostCacheColl.KeyOf(Item: Pointer): Pointer;
Expand All @@ -3041,6 +3061,7 @@ function GetHostNameByAddr(Addr: DWORD): AnsiString;
HostName: AnsiString;
begin
HostCache.Enter;
I := -1;
F := HostCache.Search(Pointer(Addr), I);
if F then
Result := StrAsg(THostCache(HostCache[I]).Name);
Expand Down

0 comments on commit 6afaf7f

Please sign in to comment.