1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

Types and casts safe in respect to pointer size for forward 64-bit compatibility (2nd after a2119a7e)

https://winscp.net/tracker/618

Source commit: c34c42432b77f29fc4e5f6824021c9d282a19525
This commit is contained in:
Martin Prikryl
2026-03-27 17:25:26 +00:00
parent 1e3ad4d70c
commit bdc1aefa86
19 changed files with 43 additions and 47 deletions

View File

@@ -81,7 +81,7 @@ struct TConsoleCommStruct
bool Error; // TRANSFERIN only
};
size_t Size;
unsigned int Size;
int Version;
enum { NONE, PRINT, INPUT, CHOICE, TITLE, INIT, PROGRESS, TRANSFEROUT, TRANSFERIN } Event;

View File

@@ -162,14 +162,11 @@ bool WindowsValidateCertificate(const unsigned char * Certificate, size_t Len, U
CERT_CHAIN_ENGINE_CONFIG ChainConfig;
memset(&ChainConfig, 0, sizeof(ChainConfig));
const size_t ChainConfigSize =
reinterpret_cast<const char *>(&ChainConfig.CycleDetectionModulus) + sizeof(ChainConfig.CycleDetectionModulus) -
reinterpret_cast<const char *>(&ChainConfig);
// The hExclusiveRoot and hExclusiveTrustedPeople were added in Windows 7.
// The CertGetCertificateChain fails with E_INVALIDARG when we include them to ChainConfig.cbSize.
// The dwExclusiveFlags was added in Windows 8
const size_t ChainConfigSize = RTL_SIZEOF_THROUGH_FIELD(CERT_CHAIN_ENGINE_CONFIG, CycleDetectionModulus);
DebugAssert(ChainConfigSize == 40);
DebugAssert(ChainConfigSize == sizeof(CERT_CHAIN_ENGINE_CONFIG) - sizeof(ChainConfig.hExclusiveRoot) - sizeof(ChainConfig.hExclusiveTrustedPeople) - sizeof(ChainConfig.dwExclusiveFlags));
ChainConfig.cbSize = ChainConfigSize;
ChainConfig.hRestrictedRoot = NULL;
ChainConfig.hRestrictedTrust = NULL;

View File

@@ -226,7 +226,7 @@ bool __fastcall TFileZillaIntf::FileTransfer(
Transfer.server = *FServer;
// 1 = ascii, 2 = binary
Transfer.nType = Type;
Transfer.nUserData = reinterpret_cast<int>(UserData);
Transfer.nUserData = reinterpret_cast<NativeInt>(UserData);
Transfer.OnTransferOut = OnTransferOut;
Transfer.OnTransferIn = OnTransferIn;

View File

@@ -38,7 +38,7 @@ typedef struct
__int64 size;
t_server server;
int nType;
int nUserData;
NativeInt nUserData;
TTransferOutEvent OnTransferOut;
TTransferInEvent OnTransferIn;
} t_transferfile;

View File

@@ -276,7 +276,7 @@ void __fastcall TConsoleDialog::DoAdjustWindow()
{
GetTextMetrics(DC, &TM);
OutputMemo->Perform(EM_GETRECT, 0, reinterpret_cast<int>(&Rect));
OutputMemo->Perform(EM_GETRECT, 0, reinterpret_cast<NativeInt>(&Rect));
}
__finally
{

View File

@@ -1924,8 +1924,8 @@ void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
Item->Hint = DView->HistoryPath[Data.Index];
DebugAssert(sizeof(int) == sizeof(THistoryItemData));
Item->Tag = *reinterpret_cast<int*>(&Data);
DebugAssert(sizeof(Item->Tag) >= sizeof(Data));
Item->Tag = *reinterpret_cast<NativeInt*>(&Data);
Item->OnClick = HistoryItemClick;
Menu->Items->Add(Item);
}
@@ -7565,7 +7565,7 @@ void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationU
if (IsSessionTab)
{
TTerminal * Terminal = Manager->Sessions[Index];
TabSheet->Tag = reinterpret_cast<int>(Terminal);
TabSheet->Tag = reinterpret_cast<NativeInt>(Terminal);
TabSheet->CaptionTruncation = WinConfiguration->SessionTabCaptionTruncation ? tttEllipsis : tttNone;
UpdateSessionTab(TabSheet);
@@ -11391,7 +11391,7 @@ void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
Item->Caption = EscapeHotkey(Directory);
Item->ShortCut = Bookmark->ShortCut;
Item->OnClick = OnBookmarkClick;
Item->Tag = reinterpret_cast<int>(Bookmark);
Item->Tag = reinterpret_cast<NativeInt>(Bookmark);
Directories->Add(Directory);
Menu->Add(Item.release());
}
@@ -11435,7 +11435,7 @@ void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
Item->Caption = Bookmark->Name;
Item->ShortCut = Bookmark->ShortCut;
Item->OnClick = OnBookmarkClick;
Item->Tag = reinterpret_cast<int>(Bookmark);
Item->Tag = reinterpret_cast<NativeInt>(Bookmark);
if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
(Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))

View File

@@ -309,7 +309,7 @@ void __fastcall TEditorRichEdit::WMPaste()
{
// replacement for EM_PASTESPECIAL,
// which ignores trailing line end for some reason
Perform(EM_REPLACESEL, true, reinterpret_cast<int>(Text));
Perform(EM_REPLACESEL, true, reinterpret_cast<NativeInt>(Text));
}
__finally
{
@@ -1537,7 +1537,7 @@ bool __fastcall TEditorForm::CursorInUpperPart()
{
GetTextMetrics(DC, &TM);
EditorMemo->Perform(EM_GETRECT, 0, reinterpret_cast<int>(&Rect));
EditorMemo->Perform(EM_GETRECT, 0, reinterpret_cast<NativeInt>(&Rect));
}
__finally
{

View File

@@ -1567,7 +1567,7 @@ void __fastcall TNonVisualDataModule::CreateOpenedSessionListMenu(TAction * Acti
DebugAssert(Session != NULL);
TTBCustomItem * Item = new TTBXItem(OpenedSessionsMenu);
Item->Caption = SessionList->Strings[Index];
Item->Tag = int(Session);
Item->Tag = reinterpret_cast<NativeInt>(Session);
Item->Hint = FMTLOAD(OPENED_TAB_HINT, (Item->Caption));
Item->Checked = (Manager->ActiveSession == Session);
Item->ShortCut = OpenSessionShortCut(Index);
@@ -2004,7 +2004,7 @@ void __fastcall TNonVisualDataModule::CreateToolbarButtonsList()
Item = new TTBXItem(CustomizeItem);
Item->Caption = StripEllipsis(ButtonItem->Caption);
Item->ImageIndex = ButtonItem->ImageIndex;
Item->Tag = reinterpret_cast<int>(ButtonItem);
Item->Tag = reinterpret_cast<NativeInt>(ButtonItem);
Item->OnClick = ToolbarButtonItemClick;
Item->Checked = ButtonItem->Visible;
}

View File

@@ -806,7 +806,7 @@ void __fastcall TSiteAdvancedDialog::UpdateNavigationTree()
}
Node->Text = Label;
Node->SelectedIndex = reinterpret_cast<int>(Tab);
Node->Data = Tab;
PrevNode = Node;
if (PageControl->ActivePage == Tab)
{
@@ -1155,7 +1155,7 @@ void __fastcall TSiteAdvancedDialog::NavigationTreeChange(TObject * /*Sender*/,
{
TAutoNestingCounter Guard(NoUpdate);
TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
TTabSheet * Tab = static_cast<TTabSheet *>(Node->Data);
// should happen only while loading language
// (UpdateNavigationTree may not be called yet)
if (Tab != NULL)
@@ -1186,8 +1186,7 @@ void __fastcall TSiteAdvancedDialog::PageChanged()
{
for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
{
if (NavigationTree->Items->Item[Index]->SelectedIndex ==
reinterpret_cast<int>(PageControl->ActivePage))
if (NavigationTree->Items->Item[Index]->Data == PageControl->ActivePage)
{
NavigationTree->Items->Item[Index]->Selected = true;
Found = true;

View File

@@ -1858,16 +1858,16 @@ begin
(not FMessageHooked) and ((FSourceEffects <> 0) or (FTargetEffects <> 0)) then
begin
WndProcPtr := MakeObjectInstance(WndMethod);
OldWndProc := Pointer(SetWindowLong(FDragDropControl.Handle, GWL_WNDPROC, LongInt(WndProcPtr)));
OldWndProc := Pointer(SetWindowLongPtr(FDragDropControl.Handle, GWLP_WNDPROC, NativeInt(WndProcPtr)));
FMessageHooked := True;
end;
end;
procedure TDragDrop.UnhookMessageHandler(ForceUnhook: Boolean);
begin
if FMessageHooked and (ForceUnhook or ((FSourceEffects=0) and (FTargetEffects=0))) then
if FMessageHooked and (ForceUnhook or ((FSourceEffects = 0) and (FTargetEffects = 0))) then
begin
SetWindowLong(FDragDropControl.Handle, GWL_WNDPROC, LongInt(OldWndProc));
SetWindowLongPtr(FDragDropControl.Handle, GWLP_WNDPROC, NativeInt(OldWndProc));
FreeObjectInstance(WndProcPtr);
WndProcPtr := nil;
OldWndProc := nil;

View File

@@ -2162,7 +2162,7 @@ begin
try
Screen.Cursor := crHourglass;
FNotifyEnabled := False;
CustomSort(SortProc, Integer(Pointer(Self)));
CustomSort(SortProc, NativeInt(Self));
finally
Screen.Cursor := SavedCursor;
FNotifyEnabled := SavedNotifyEnabled;

View File

@@ -81,7 +81,7 @@ begin
end;
end;
function ThreadWndProc(Window: HWND; Message, wParam, lParam: Longint): Longint; stdcall;
function ThreadWndProc(Window: HWND; Message: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
case Message of
CM_EXECPROC:
@@ -305,7 +305,7 @@ procedure TCompThread.Synchronize(Method: TThreadMethod);
begin
FSynchronizeException := nil;
FMethod := Method;
SendMessage(ThreadWindow, CM_EXECPROC, 0, Longint(Self));
SendMessage(ThreadWindow, CM_EXECPROC, 0, LPARAM(Self));
if Assigned(FSynchronizeException) then raise FSynchronizeException;
end;

View File

@@ -414,7 +414,7 @@ begin
SetRect(Loc, GetButtonWidth + 1, 0, ClientWidth - 1, ClientHeight + 1)
else
SetRect(Loc, 0, 0, ClientWidth - GetButtonWidth - 2, ClientHeight + 1);
SendMessage(Handle, EM_SETRECTNP, 0, Longint(@Loc));
SendMessage(Handle, EM_SETRECTNP, 0, LPARAM(@Loc));
end;
procedure TUpDownEdit.SetAlignment(Value: TAlignment);

View File

@@ -33,7 +33,7 @@ uses
type
TListSortExCompare = function(const Item1, Item2, ExtraData: Pointer): Integer;
THandleWMPrintNCPaintProc = procedure(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
THandleWMPrintNCPaintProc = procedure(Control: TControl; Wnd: HWND; DC: HDC; AppData: NativeUInt);
function AddToFrontOfList(var List: TList; Item: Pointer): Boolean;
function AddToList(var List: TList; Item: Pointer): Boolean;
@@ -61,7 +61,7 @@ function GetRectOfPrimaryMonitor(const WorkArea: Boolean): TRect;
function GetTextHeight(const DC: HDC): Integer;
function GetTextWidth(const DC: HDC; S: String; const Prefix: Boolean): Integer;
procedure HandleWMPrint(Control: TControl; const Wnd: HWND; var Message: TMessage;
const NCPaintFunc: THandleWMPrintNCPaintProc; const AppData: Longint);
const NCPaintFunc: THandleWMPrintNCPaintProc; const AppData: NativeUInt);
procedure HandleWMPrintClient(const Control: TWinControl;
var Message: TMessage);
procedure ListSortEx(const List: TList; const Compare: TListSortExCompare;
@@ -168,7 +168,7 @@ begin
end;
procedure HandleWMPrint(Control: TControl; const Wnd: HWND; var Message: TMessage;
const NCPaintFunc: THandleWMPrintNCPaintProc; const AppData: Longint);
const NCPaintFunc: THandleWMPrintNCPaintProc; const AppData: NativeUInt);
{ note: AppData is an application-defined value which is passed to NCPaintFunc }
var
DC: HDC;

View File

@@ -1759,14 +1759,14 @@ begin
DrawNCArea(False, 0, HRGN(Message.WParam));
end;
procedure DockNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
procedure DockNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: NativeUInt);
begin
TTBDock(AppData).DrawNCArea(True, DC, 0);
end;
procedure TTBDock.WMPrint(var Message: TMessage);
begin
HandleWMPrint(Self, Handle, Message, DockNCPaintProc, Longint(Self));
HandleWMPrint(Self, Handle, Message, DockNCPaintProc, NativeUInt(Self));
end;
procedure TTBDock.WMPrintClient(var Message: TMessage);
@@ -2051,7 +2051,7 @@ begin
DrawNCArea(False, 0, HRGN(Message.WParam), twrdAll);
end;
procedure FloatingWindowParentNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
procedure FloatingWindowParentNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: NativeUInt);
begin
with TTBFloatingWindowParent(AppData) do
DrawNCArea(True, DC, 0, twrdAll);
@@ -2059,7 +2059,7 @@ end;
procedure TTBFloatingWindowParent.WMPrint(var Message: TMessage);
begin
HandleWMPrint(Self, Handle, Message, FloatingWindowParentNCPaintProc, Longint(Self));
HandleWMPrint(Self, Handle, Message, FloatingWindowParentNCPaintProc, NativeUInt(Self));
end;
procedure TTBFloatingWindowParent.WMPrintClient(var Message: TMessage);
@@ -3489,7 +3489,7 @@ begin
DrawNCArea(False, 0, HRGN(Message.WParam));
end;
procedure DockableWindowNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
procedure DockableWindowNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: NativeUInt);
begin
with TTBCustomDockableWindow(AppData) do
DrawNCArea(True, DC, 0)
@@ -3497,7 +3497,7 @@ end;
procedure TTBCustomDockableWindow.WMPrint(var Message: TMessage);
begin
HandleWMPrint(Self, Handle, Message, DockableWindowNCPaintProc, Longint(Self));
HandleWMPrint(Self, Handle, Message, DockableWindowNCPaintProc, NativeUInt(Self));
end;
procedure TTBCustomDockableWindow.WMPrintClient(var Message: TMessage);

View File

@@ -3596,7 +3596,7 @@ end;
function TTBView.HandleWMGetObject(var Message: TMessage): Boolean;
begin
if (Message.LParam = Integer(OBJID_CLIENT)) then begin
if (Integer(Message.LParam) = Integer(OBJID_CLIENT)) then begin
Message.Result := LresultFromObject(ITBAccessible, Message.WParam, GetAccObject);
Result := True;
end
@@ -6688,7 +6688,7 @@ begin
inherited;
end;
procedure PopupWindowNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
procedure PopupWindowNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: NativeUInt);
var
R: TRect;
{$IFNDEF TB2K_USE_STRICT_O2K_MENU_STYLE}
@@ -6722,7 +6722,7 @@ begin
DC := GetWindowDC(Handle);
try
SelectNCUpdateRgn(Handle, DC, HRGN(Message.WParam));
PopupWindowNCPaintProc(Self, Handle, DC, Longint(Self));
PopupWindowNCPaintProc(Self, Handle, DC, NativeUInt(Self));
finally
ReleaseDC(Handle, DC);
end;
@@ -6730,7 +6730,7 @@ end;
procedure TTBPopupWindow.WMPrint(var Message: TMessage);
begin
HandleWMPrint(Self, Handle, Message, PopupWindowNCPaintProc, Longint(Self));
HandleWMPrint(Self, Handle, Message, PopupWindowNCPaintProc, NativeUInt(Self));
end;
procedure TTBPopupWindow.WMPrintClient(var Message: TMessage);

View File

@@ -2306,7 +2306,7 @@ begin
Message.Result := 1;
end;
procedure TBXPopupNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
procedure TBXPopupNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: NativeUInt);
var
R, R2: TRect;
Canvas: TCanvas;
@@ -2367,7 +2367,7 @@ begin
try
Assert(DC <> 0, 'TTBXPopupWindow.WMNCPaint');
SelectNCUpdateRgn(Handle, DC, HRGN(Message.WParam));
TBXPopupNCPaintProc(Self, Handle, DC, LongInt(Self.View));
TBXPopupNCPaintProc(Self, Handle, DC, NativeUInt(Self.View));
finally
ReleaseDC(Handle, DC);
end;
@@ -2375,7 +2375,7 @@ end;
procedure TTBXPopupWindow.WMPrint(var Message: TMessage);
begin
HandleWMPrint(Self, Handle, Message, TBXPopupNCPaintProc, LongInt(Self.View));
HandleWMPrint(Self, Handle, Message, TBXPopupNCPaintProc, NativeUInt(Self.View));
end;
procedure TTBXPopupWindow.WMTB2kPopupShowing(var Message: TMessage);

View File

@@ -1035,7 +1035,7 @@ void __fastcall CreateColorPalette(TTBCustomItem * Owner, TColor Color, int Rows
ColorSet->ColCount = ColorCols;
ColorSet->RowCount = Rows;
ColorSet->OnGetColorInfo = OnGetColorInfo;
ColorSet->Tag = static_cast<int>(SessionColors);
ColorSet->Tag = static_cast<NativeInt>(SessionColors);
}
// clNone = no selection, see also ColorChange

View File

@@ -753,7 +753,7 @@ static void __fastcall FormShowingChanged(TForm * Form, TWndMethod WndProc, TMes
{
Form->Caption = FormatFormCaption(Form, Form->Caption);
}
SendMessage(Form->Handle, WM_SETICON, ICON_BIG, reinterpret_cast<long>(Application->Icon->Handle));
SendMessage(Form->Handle, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(Application->Icon->Handle));
}
else
{
@@ -2100,7 +2100,7 @@ void __fastcall InvokeHelp(TWinControl * Control)
HelpInfo.dwContextId = 0;
HelpInfo.MousePos.x = 0;
HelpInfo.MousePos.y = 0;
SendMessage(Control->Handle, WM_HELP, NULL, reinterpret_cast<long>(&HelpInfo));
SendMessage(Control->Handle, WM_HELP, NULL, reinterpret_cast<LPARAM>(&HelpInfo));
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------