From 99c1e30b5cb0843155a275fe1aa05647fad56342 Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Mon, 13 Dec 2021 02:33:06 +0000 Subject: [PATCH] Refactoring --- far/PluginA.cpp | 75 ++++++++++++++++++------------------ far/cddrv.cpp | 16 ++++---- far/changelog | 5 +++ far/clipboard.cpp | 6 +-- far/codepage_selection.cpp | 2 +- far/common.tests.cpp | 2 +- far/common/io.hpp | 2 +- far/common/nifty_counter.hpp | 2 +- far/common/smart_ptr.hpp | 2 +- far/common/utility.hpp | 48 +++++++++++++++-------- far/config.cpp | 2 +- far/copy.cpp | 6 +-- far/delete.cpp | 2 +- far/dialog.cpp | 11 +++--- far/editor.cpp | 2 +- far/exception_handler.cpp | 10 ++--- far/fileedit.cpp | 10 ++--- far/filefilterparams.cpp | 16 ++++---- far/filelist.cpp | 8 ++-- far/filetype.cpp | 2 +- far/findfile.cpp | 8 ++-- far/flink.cpp | 6 +-- far/hotplug.cpp | 4 +- far/infolist.cpp | 4 +- far/macro.cpp | 16 ++++---- far/main.cpp | 2 +- far/memcheck.cpp | 6 +-- far/message.cpp | 2 +- far/panel.cpp | 6 +-- far/platform.cpp | 4 +- far/platform.fs.cpp | 22 +++++------ far/platform.reg.cpp | 2 +- far/platform.version.cpp | 2 +- far/plist.cpp | 2 +- far/plugapi.cpp | 10 ++--- far/plugins.cpp | 23 +++++------ far/print.cpp | 4 +- far/setattr.cpp | 8 ++-- far/setcolor.cpp | 2 +- far/stddlg.cpp | 2 +- far/string_sort.hpp | 2 + far/usermenu.cpp | 4 +- far/vbuild.m4 | 2 +- far/viewer.cpp | 36 ++++++++--------- far/wm_listener.cpp | 6 +-- 45 files changed, 221 insertions(+), 193 deletions(-) diff --git a/far/PluginA.cpp b/far/PluginA.cpp index debba18631..cdbd1e8a8d 100644 --- a/far/PluginA.cpp +++ b/far/PluginA.cpp @@ -711,7 +711,7 @@ static PluginPanelItem* ConvertAnsiPanelItemsToUnicode(span(Src.UserData); + const auto UserData = view_as(Src.UserData); const auto Size = *static_cast(UserData); Dst.UserData.Data = new char[Size]; copy_memory(UserData, Dst.UserData.Data, Size); @@ -810,7 +810,7 @@ static void FreePanelItemA(span const PanelItem) if (Item.Flags & oldfar::PPIF_USERDATA) { - delete[] reinterpret_cast(Item.UserData); + delete[] edit_as(Item.UserData); } } @@ -838,7 +838,7 @@ static char *InsertQuoteA(char *Str) static auto GetPluginUuid(intptr_t n) { - return &reinterpret_cast(n)->Id(); + return &view_as(n).Id(); } struct DialogData @@ -892,12 +892,12 @@ static size_t GetAnsiVBufSize(const oldfar::FarDialogItem &diA) static auto GetAnsiVBufPtr(FAR_CHAR_INFO* VBuf, size_t Size) { - return VBuf? *reinterpret_cast(&VBuf[Size]) : nullptr; + return VBuf? *edit_as(&VBuf[Size]) : nullptr; } static void SetAnsiVBufPtr(FAR_CHAR_INFO* VBuf, CHAR_INFO* VBufA, size_t Size) { - *reinterpret_cast(&VBuf[Size]) = VBufA; + *edit_as(&VBuf[Size]) = VBufA; } static void AnsiVBufToUnicode(CHAR_INFO* VBufA, FAR_CHAR_INFO* VBuf, size_t Size, bool NoCvt) @@ -1508,7 +1508,7 @@ struct FAR_SEARCH_A_CALLBACK_PARAM void *Param; }; -static const char* GetPluginMsg(const Plugin* PluginInstance, int MsgId); +static const char* GetPluginMsg(const Plugin& PluginInstance, int MsgId); namespace oldpluginapi { @@ -2402,7 +2402,7 @@ static int WINAPI FarMessageFnA(intptr_t PluginNumber, DWORD Flags, const char * if (Flags&oldfar::FMSG_ALLINONE) { - AllInOneAnsiItem.reset(AnsiToUnicode(reinterpret_cast(Items))); + AllInOneAnsiItem.reset(AnsiToUnicode(view_as(Items))); } else { @@ -2449,7 +2449,7 @@ static int WINAPI FarMessageFnA(intptr_t PluginNumber, DWORD Flags, const char * &FarUuid, NewFlags, HelpTopic? encoding::oem::get_chars(HelpTopic).c_str() : nullptr, - AnsiItems.empty()? reinterpret_cast(AllInOneAnsiItem.get()) : reinterpret_cast(AnsiItems.data()), + view_as(AnsiItems.empty()? AllInOneAnsiItem.get() : AnsiItems.data()->get()), ItemsNumber, ButtonsNumber ); @@ -2461,17 +2461,17 @@ static int WINAPI FarMessageFnA(intptr_t PluginNumber, DWORD Flags, const char * }); } -static const char * WINAPI FarGetMsgFnA(intptr_t PluginHandle, int MsgId) noexcept +static const char* WINAPI FarGetMsgFnA(intptr_t PluginHandle, int MsgId) noexcept { return cpp_try( [&] { //BUGBUG, надо проверять, что PluginHandle - плагин - const auto pPlugin = reinterpret_cast(PluginHandle); - string_view Path = pPlugin->ModuleName(); + auto& pPlugin = edit_as(PluginHandle); + string_view Path = pPlugin.ModuleName(); CutToSlash(Path); - if (pPlugin->InitLang(Path, Global->Opt->strLanguage)) + if (pPlugin.InitLang(Path, Global->Opt->strLanguage)) return GetPluginMsg(pPlugin, MsgId); return ""; @@ -2516,7 +2516,7 @@ static int WINAPI FarMenuFnA(intptr_t PluginNumber, int X, int Y, int MaxHeight, OLDFAR_TO_FAR_MAP(MIF_HIDDEN), }; - for (const auto& [Item, AnsiItem]: zip(mi, span(reinterpret_cast(Items), ItemsNumber))) + for (const auto& [Item, AnsiItem]: zip(mi, span(view_as(Items), ItemsNumber))) { Item.Flags = MIF_NONE; FirstFlagsToSecond(AnsiItem.Flags, Item.Flags, ItemFlagsMap); @@ -2544,7 +2544,7 @@ static int WINAPI FarMenuFnA(intptr_t PluginNumber, int X, int Y, int MaxHeight, Item.Flags |= MIF_CHECKED; if (AnsiItem.Checked > 1) - AnsiToUnicodeBin({ reinterpret_cast(&AnsiItem.Checked), 1 }, reinterpret_cast(&Item.Flags)); + AnsiToUnicodeBin({ view_as(&AnsiItem.Checked), 1 }, edit_as(&Item.Flags)); } if (AnsiItem.Separator) @@ -2752,7 +2752,7 @@ static intptr_t WINAPI DlgProcA(HANDLE hDlg, intptr_t NewMsg, intptr_t Param1, v if (ret && ret != reinterpret_cast(Param2)) // changed { static std::unique_ptr HelpTopic; - HelpTopic.reset(AnsiToUnicode(reinterpret_cast(ret))); + HelpTopic.reset(AnsiToUnicode(view_as(ret))); ret = reinterpret_cast(HelpTopic.get()); } return ret; @@ -3149,7 +3149,8 @@ static intptr_t WINAPI FarSendDlgMessageA(HANDLE hDlg, int OldMsg, int Param1, v { intptr_t Size = pluginapi::apiSendDlgMessage(hDlg, DM_LISTGETDATASIZE, Param1, Param2); intptr_t Data = pluginapi::apiSendDlgMessage(hDlg, DM_LISTGETDATA, Param1, Param2); - if(Size<=4) Data=Data?*reinterpret_cast(Data):0; + if (Size <= 4) + Data = Data? view_as(Data) : 0; return Data; } case oldfar::DM_LISTSETDATA: @@ -4843,15 +4844,15 @@ static int WINAPI FarCharTableA(int Command, char *Buffer, int BufferSize) noexc if (BufferSize != static_cast(sizeof(oldfar::CharTableSet))) return -1; - const auto TableSet = reinterpret_cast(Buffer); + auto& TableSet = edit_as(Buffer); //Preset. Also if Command != FCT_DETECT and failed, buffer must be filled by OEM data. - strcpy(TableSet->TableName,""); + strcpy(TableSet.TableName,""); for (const auto& i: irange(256u)) { - TableSet->EncodeTable[i] = TableSet->DecodeTable[i] = i; - TableSet->UpperTable[i] = LocalUpper(i); - TableSet->LowerTable[i] = LocalLower(i); + TableSet.EncodeTable[i] = TableSet.DecodeTable[i] = i; + TableSet.UpperTable[i] = LocalUpper(i); + TableSet.LowerTable[i] = LocalLower(i); } const auto nCP = ConvertCharTableToCodePage(Command); @@ -4864,17 +4865,17 @@ static int WINAPI FarCharTableA(int Command, char *Buffer, int BufferSize) noexc auto sTableName = pad_right(str(nCP), 5); append(sTableName, BoxSymbols[BS_V1], L' ', Info->Name); - (void)encoding::oem::get_bytes(sTableName, TableSet->TableName); - std::unique_ptr const us(AnsiToUnicodeBin({ reinterpret_cast(TableSet->DecodeTable), std::size(TableSet->DecodeTable) }, nCP)); + (void)encoding::oem::get_bytes(sTableName, TableSet.TableName); + std::unique_ptr const us(AnsiToUnicodeBin({ edit_as(TableSet.DecodeTable), std::size(TableSet.DecodeTable) }, nCP)); - inplace::lower({ us.get(), std::size(TableSet->DecodeTable) }); - (void)encoding::get_bytes(nCP, { us.get(), std::size(TableSet->DecodeTable) }, { reinterpret_cast(TableSet->LowerTable), std::size(TableSet->DecodeTable) }); + inplace::lower({ us.get(), std::size(TableSet.DecodeTable) }); + (void)encoding::get_bytes(nCP, { us.get(), std::size(TableSet.DecodeTable) }, { edit_as(TableSet.LowerTable), std::size(TableSet.DecodeTable) }); - inplace::upper({ us.get(), std::size(TableSet->DecodeTable) }); - (void)encoding::get_bytes(nCP, { us.get(), std::size(TableSet->DecodeTable) }, { reinterpret_cast(TableSet->UpperTable), std::size(TableSet->DecodeTable) }); + inplace::upper({ us.get(), std::size(TableSet.DecodeTable) }); + (void)encoding::get_bytes(nCP, { us.get(), std::size(TableSet.DecodeTable) }, { edit_as(TableSet.UpperTable), std::size(TableSet.DecodeTable) }); - MultiByteRecode(nCP, encoding::codepage::oem(), { reinterpret_cast(TableSet->DecodeTable), std::size(TableSet->DecodeTable) }); - MultiByteRecode(encoding::codepage::oem(), nCP, { reinterpret_cast(TableSet->EncodeTable), std::size(TableSet->EncodeTable) }); + MultiByteRecode(nCP, encoding::codepage::oem(), { edit_as(TableSet.DecodeTable), std::size(TableSet.DecodeTable) }); + MultiByteRecode(encoding::codepage::oem(), nCP, { edit_as(TableSet.EncodeTable), std::size(TableSet.EncodeTable) }); return Command; } return -1; @@ -5091,7 +5092,7 @@ class PluginA final: public Plugin while (nb > 0) { --nb; - reinterpret_cast(&Info->Guid)[8 + nb] = static_cast(Info->Title[nb]); + edit_as(&Info->Guid)[8 + nb] = static_cast(Info->Title[nb]); } } @@ -5238,7 +5239,7 @@ WARNING_POP() OpenFromA = oldfar::OPEN_COMMANDLINE; if (Info->Data) { - Buffer.reset(UnicodeToAnsi(reinterpret_cast(Info->Data)->CommandLine)); + Buffer.reset(UnicodeToAnsi(view_as(Info->Data).CommandLine)); Ptr = reinterpret_cast(Buffer.get()); } break; @@ -5247,8 +5248,8 @@ WARNING_POP() OpenFromA = oldfar::OPEN_SHORTCUT; if (Info->Data) { - const auto SInfo = reinterpret_cast(Info->Data); - const auto shortcutdata = SInfo->ShortcutData ? SInfo->ShortcutData : SInfo->HostFile; + const auto& SInfo = view_as(Info->Data); + const auto shortcutdata = SInfo.ShortcutData? SInfo.ShortcutData : SInfo.HostFile; Buffer.reset(UnicodeToAnsi(shortcutdata)); Ptr = reinterpret_cast(Buffer.get()); } @@ -5292,14 +5293,14 @@ WARNING_POP() case OPEN_FROMMACRO: // BUGBUG this is not how it worked in 1.7 OpenFromA = static_cast(oldfar::OPEN_FROMMACRO) | static_cast(Global->CtrlObject->Macro.GetArea()); - Buffer.reset(UnicodeToAnsi(reinterpret_cast(Info->Data)->Count ? reinterpret_cast(Info->Data)->Values[0].String : L"")); + Buffer.reset(UnicodeToAnsi(view_as(Info->Data).Count? view_as(Info->Data).Values[0].String : L"")); Ptr = reinterpret_cast(Buffer.get()); break; case OPEN_DIALOG: OpenFromA = oldfar::OPEN_DIALOG; DlgData.ItemNumber = Info->Guid->Data1; - DlgData.hDlg = reinterpret_cast(Info->Data)->hDlg; + DlgData.hDlg = view_as(Info->Data).hDlg; Ptr = reinterpret_cast(&DlgData); break; @@ -6022,9 +6023,9 @@ WARNING_POP() bool opif_shortcut{}; }; -static const char* GetPluginMsg(const Plugin* PluginInstance, int MsgId) +static const char* GetPluginMsg(const Plugin& PluginInstance, int MsgId) { - return static_cast(PluginInstance)->GetMsgA(MsgId); + return static_cast(PluginInstance).GetMsgA(MsgId); } std::unique_ptr oem_plugin_factory::CreatePlugin(const string& FileName) diff --git a/far/cddrv.cpp b/far/cddrv.cpp index 04261840b3..12888d1941 100644 --- a/far/cddrv.cpp +++ b/far/cddrv.cpp @@ -112,14 +112,6 @@ static auto read_value_from_big_endian(unsigned char const (&Src)[N]) return read_value_from_big_endian_impl(Src, std::make_index_sequence{}); } -template -static auto& edit_as(void* const Buffer) -{ - static_assert(std::is_trivially_copyable_v); - - return *static_cast(Buffer); -} - struct SCSI_PASS_THROUGH_WITH_BUFFERS: SCSI_PASS_THROUGH { UCHAR SenseBuf[32]; @@ -195,6 +187,14 @@ WARNING_DISABLE_CLANG("-Wswitch") WARNING_POP() } +template +static auto view_as_if(container const& Buffer, intptr_t const Offset = 0) +{ + static_assert(std::is_trivially_copyable_v); + + return Buffer.size() >= Offset + sizeof(T)? view_as(Buffer.data() + Offset) : nullptr; +} + static auto capatibilities_from_scsi_configuration(const os::fs::file& Device) { SCSI_PASS_THROUGH_WITH_BUFFERS Spt; diff --git a/far/changelog b/far/changelog index 926a2e6db6..bf3d1285ab 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,8 @@ +-------------------------------------------------------------------------------- +drkns 13.12.2021 02:32:37 +0000 - build 5932 + +1. Refactoring. + -------------------------------------------------------------------------------- drkns 10.12.2021 23:51:14 +0000 - build 5931 diff --git a/far/clipboard.cpp b/far/clipboard.cpp index f4fcd98de1..1007dfe09c 100644 --- a/far/clipboard.cpp +++ b/far/clipboard.cpp @@ -372,7 +372,7 @@ bool clipboard::SetHDROP(const string_view NamesData, const bool bMoved) Drop->pt.y = 0; Drop->fNC = TRUE; Drop->fWide = TRUE; - *copy_string(NamesData, static_cast(static_cast(Drop.get() + 1))) = {}; + *copy_string(NamesData, edit_as(Drop.get() + 1)) = {}; if (!Clear() || !SetData(CF_HDROP, std::move(Memory))) return false; @@ -429,12 +429,12 @@ bool clipboard::GetHDROPAsText(string& data) const if (!Files) return false; - const auto StartA=reinterpret_cast(Files.get()) + Files->pFiles; + const auto StartA = view_as(Files.get(), Files->pFiles); const auto Eol = eol::system.str(); if (Files->fWide) { - const auto Start = reinterpret_cast(StartA); + const auto Start = view_as(StartA); for (const auto& i: enum_substrings(Start)) { diff --git a/far/codepage_selection.cpp b/far/codepage_selection.cpp index e75138c4b2..d457702afb 100644 --- a/far/codepage_selection.cpp +++ b/far/codepage_selection.cpp @@ -592,7 +592,7 @@ intptr_t codepages::EditDialogProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, v if (Param1 == EDITCP_OK) { - strCodePageName = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, EDITCP_EDIT, nullptr)); + strCodePageName = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, EDITCP_EDIT, nullptr)); } // Если имя кодовой страницы пустое, то считаем, что имя не задано if (strCodePageName.empty()) diff --git a/far/common.tests.cpp b/far/common.tests.cpp index 197a060413..4a3a480d5d 100644 --- a/far/common.tests.cpp +++ b/far/common.tests.cpp @@ -651,7 +651,7 @@ TEST_CASE("placement") }; std::aligned_storage_t Data; - auto& Object = reinterpret_cast(Data); + auto& Object = edit_as(&Data); int Value = 0; placement::construct(Object, Value); diff --git a/far/common/io.hpp b/far/common/io.hpp index c45339fede..7fedfdea66 100644 --- a/far/common/io.hpp +++ b/far/common/io.hpp @@ -69,7 +69,7 @@ namespace io { try { - Stream.read(static_cast(static_cast(Buffer.data())), Buffer.size()); + Stream.read(edit_as(Buffer.data()), Buffer.size()); } catch (std::ios::failure const&) { diff --git a/far/common/nifty_counter.hpp b/far/common/nifty_counter.hpp index b4251e7364..49af8430c7 100644 --- a/far/common/nifty_counter.hpp +++ b/far/common/nifty_counter.hpp @@ -75,6 +75,6 @@ namespace Instance##_nifty_objects\ }\ }\ \ -Type& Instance = reinterpret_cast(Instance##_nifty_objects::InitBuffer) +Type& Instance = *static_cast(static_cast(&Instance##_nifty_objects::InitBuffer)) #endif // NIFTY_COUNTER_HPP_81EED24A_897B_4E3E_A23D_4117272E29D9 diff --git a/far/common/smart_ptr.hpp b/far/common/smart_ptr.hpp index 365bf4c392..5e1c89773a 100644 --- a/far/common/smart_ptr.hpp +++ b/far/common/smart_ptr.hpp @@ -161,7 +161,7 @@ class block_ptr: public array_ptr decltype(auto) data() const noexcept { assert(this->size() >= sizeof(T)); - return static_cast(static_cast((array_ptr::data()))); + return edit_as(array_ptr::data()); } [[nodiscard]] diff --git a/far/common/utility.hpp b/far/common/utility.hpp index 508e622b3b..cc341c79e0 100644 --- a/far/common/utility.hpp +++ b/far/common/utility.hpp @@ -285,35 +285,51 @@ void copy_memory(const src_type* Source, dst_type* Destination, size_t const Siz std::memmove(Destination, Source, Size); } -template -decltype(auto) view_as(void const* const BaseAddress, size_t const Offset = 0) +namespace detail { - static_assert(std::is_trivially_copyable_v); + template + decltype(auto) cast_as(void_type* const BaseAddress, intptr_t const Offset) + { + static_assert(std::is_same_v, void>); - const auto Ptr = static_cast(static_cast(BaseAddress) + Offset); + constexpr auto IsConst = std::is_const_v; - if constexpr (std::is_pointer_v) - { - return static_cast(Ptr); - } - else - { - return *static_cast(Ptr); + const auto Ptr = static_cast(static_cast*>(BaseAddress) + Offset); + + if constexpr (std::is_pointer_v) + { + return static_cast(Ptr); + } + else + { + assert(Ptr); + return *static_cast*>(Ptr); + } } + +} +template +decltype(auto) view_as(void const* const BaseAddress, intptr_t const Offset = 0) +{ + return detail::cast_as(BaseAddress, Offset); } template decltype(auto) view_as(unsigned long long const Address) { - return view_as(reinterpret_cast(Address)); + return view_as(nullptr, Address); } -template -auto view_as_if(container const& Buffer, size_t const Offset = 0) +template +decltype(auto) edit_as(void* const BaseAddress, intptr_t const Offset = 0) { - static_assert(std::is_trivially_copyable_v); + return detail::cast_as(BaseAddress, Offset); +} - return Buffer.size() >= Offset + sizeof(T)? view_as(Buffer.data() + Offset) : nullptr; +template +decltype(auto) edit_as(unsigned long long const Address) +{ + return edit_as(nullptr, Address); } template diff --git a/far/config.cpp b/far/config.cpp index 3cf492b08b..fc80eb6f0b 100644 --- a/far/config.cpp +++ b/far/config.cpp @@ -2480,7 +2480,7 @@ intptr_t Options::AdvancedConfigDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Para { return Index == -1 ? nullptr : // Everything is filtered out - reinterpret_cast(Dlg->GetListItemSimpleUserData(0, Index)); + view_as(Dlg->GetListItemSimpleUserData(0, Index)); }; const auto EditItem = [&](edit_mode const EditMode) diff --git a/far/copy.cpp b/far/copy.cpp index 4457f7fa50..e12b9ce836 100644 --- a/far/copy.cpp +++ b/far/copy.cpp @@ -519,7 +519,7 @@ intptr_t ShellCopy::CopyDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* P в списке. */ const auto MultiCopy = Dlg->SendMessage(DM_GETCHECK, ID_SC_MULTITARGET, nullptr) == BSTATE_CHECKED; - string strOldFolder = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ID_SC_TARGETEDIT, nullptr)); + string strOldFolder = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ID_SC_TARGETEDIT, nullptr)); string strNewFolder; if (AltF10 == 2) @@ -2806,7 +2806,7 @@ intptr_t ShellCopy::WarnDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* P { case DM_OPENVIEWER: { - if (const auto WFN = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr))) + if (const auto WFN = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr))) { NamesList List; List.AddName(*WFN->Src); @@ -2850,7 +2850,7 @@ intptr_t ShellCopy::WarnDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* P break; case WDLG_RENAME: { - const auto& WFN = *reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto& WFN = *view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); const auto strDestName = GenerateName(*WFN.Dest, *WFN.DestPath); if (Dlg->SendMessage(DM_GETCHECK, WDLG_CHECKBOX, nullptr) == BSTATE_UNCHECKED) diff --git a/far/delete.cpp b/far/delete.cpp index 0adb2ca209..5539232a4b 100644 --- a/far/delete.cpp +++ b/far/delete.cpp @@ -162,7 +162,7 @@ class delete_progress: progress_impl if (Files.Total) { const auto Percent = ToPercent(Files.Value, Files.Total); - const auto Title = reinterpret_cast(m_Dialog->SendMessage(DM_GETCONSTTEXTPTR, items::pr_doublebox, {})); + const auto Title = view_as(m_Dialog->SendMessage(DM_GETCONSTTEXTPTR, items::pr_doublebox, {})); m_Dialog->SendMessage(DM_SETTEXTPTR, items::pr_console_title, UNSAFE_CSTR(concat(L'{', str(Percent), L"%} "sv, Title))); m_Dialog->SendMessage(DM_SETTEXTPTR, items::pr_total_progress, UNSAFE_CSTR(make_progressbar(DlgW - 10, Percent, true, true))); } diff --git a/far/dialog.cpp b/far/dialog.cpp index 380c653ee8..ae90442210 100644 --- a/far/dialog.cpp +++ b/far/dialog.cpp @@ -229,9 +229,10 @@ static size_t ConvertItemEx2(const DialogItemEx& ItemEx, FarGetDialogItem *Item, { if (ConvertListbox) { - const auto list = static_cast(static_cast(reinterpret_cast(Item->Item) + offsetList)); - const auto listItems = static_cast(static_cast(reinterpret_cast(Item->Item) + offsetListItems)); - auto text = static_cast(static_cast(listItems + ListBoxSize)); + const auto list = edit_as(Item->Item, offsetList); + const auto listItems = edit_as(Item->Item, offsetListItems); + auto text = edit_as(listItems, ListBoxSize); + for (const auto& ii: irange(ListBoxSize)) { auto& item = ListBox->at(ii); @@ -253,7 +254,7 @@ static size_t ConvertItemEx2(const DialogItemEx& ItemEx, FarGetDialogItem *Item, } } - auto p = static_cast(static_cast(reinterpret_cast(Item->Item) + offsetStrings)); + auto p = edit_as(Item->Item, offsetStrings); Item->Item->Data = p; p += str.copy(p, str.npos); *p++ = {}; @@ -2568,7 +2569,7 @@ bool Dialog::ProcessKey(const Manager::Key& Key) // Перед выводом диалога посылаем сообщение в обработчик // и если вернули что надо, то выводим подсказку { - const auto Topic = help::make_topic(PluginOwner, NullToEmpty(reinterpret_cast(DlgProc(DN_HELP, m_FocusPos, const_cast(EmptyToNull(HelpTopic)))))); + const auto Topic = help::make_topic(PluginOwner, NullToEmpty(view_as(DlgProc(DN_HELP, m_FocusPos, const_cast(EmptyToNull(HelpTopic)))))); if (!Topic.empty()) { help::show(Topic); diff --git a/far/editor.cpp b/far/editor.cpp index a6cd94471c..65ac001cfa 100644 --- a/far/editor.cpp +++ b/far/editor.cpp @@ -6114,7 +6114,7 @@ bool Editor::InitSessionBookmarksForPlugin(EditorBookmarks* Param, size_t Count, if (!Param || Param->Size < Size) return false; - const auto data = reinterpret_cast(Param + 1); + const auto data = edit_as(Param + 1); Param->Count=Count; Param->Line=data; Param->Cursor=data+Count; diff --git a/far/exception_handler.cpp b/far/exception_handler.cpp index d77c130ffe..7517c56866 100644 --- a/far/exception_handler.cpp +++ b/far/exception_handler.cpp @@ -610,8 +610,8 @@ class [[nodiscard]] enum_catchable_objects: public enumerator(Record.ExceptionInformation[2]); - const auto& CatchableTypeArrayRef = *reinterpret_cast(m_BaseAddress + ThrowInfoRef.pCatchableTypeArray); + const auto& ThrowInfoRef = *view_as(Record.ExceptionInformation[2]); + const auto& CatchableTypeArrayRef = *view_as(m_BaseAddress + ThrowInfoRef.pCatchableTypeArray); m_CatchableTypesRVAs = { &CatchableTypeArrayRef.arrayOfCatchableTypes, static_cast(CatchableTypeArrayRef.nCatchableTypes) }; } @@ -625,8 +625,8 @@ class [[nodiscard]] enum_catchable_objects: public enumerator(m_BaseAddress + m_CatchableTypesRVAs[m_Index++]); - const auto& TypeInfoRef = *reinterpret_cast(m_BaseAddress + CatchableTypeRef.pType); + const auto& CatchableTypeRef = *view_as(m_BaseAddress + m_CatchableTypesRVAs[m_Index++]); + const auto& TypeInfoRef = *view_as(m_BaseAddress + CatchableTypeRef.pType); Name = TypeInfoRef.name(); return true; @@ -1010,7 +1010,7 @@ static bool handle_seh_exception( for (const auto& i : enum_catchable_objects(Context.exception_record())) { if (strstr(i, "std::exception")) - return handle_std_exception(Context, *reinterpret_cast(Context.exception_record().ExceptionInformation[1]), Function, PluginModule); + return handle_std_exception(Context, *view_as(Context.exception_record().ExceptionInformation[1]), Function, PluginModule); } return handle_generic_exception(Context, Function, {}, PluginModule, {}, {}); diff --git a/far/fileedit.cpp b/far/fileedit.cpp index 06ec811c04..dd28ed79ed 100644 --- a/far/fileedit.cpp +++ b/far/fileedit.cpp @@ -137,10 +137,10 @@ static intptr_t hndOpenEditor(Dialog* Dlg, intptr_t msg, intptr_t param1, void* { if (param1 == ID_OE_OK) { - const auto param = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + auto& param = edit_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); FarListPos pos{ sizeof(pos) }; Dlg->SendMessage(DM_LISTGETCURPOS, ID_OE_CODEPAGE, &pos); - *param = Dlg->GetListItemSimpleUserData(ID_OE_CODEPAGE, pos.SelectPos); + param = Dlg->GetListItemSimpleUserData(ID_OE_CODEPAGE, pos.SelectPos); return TRUE; } } @@ -237,7 +237,7 @@ static intptr_t hndSaveFileAs(Dialog* Dlg, intptr_t msg, intptr_t param1, void* { case DN_INITDIALOG: { - CurrentCodepage = *reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + CurrentCodepage = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); codepages::instance().FillCodePagesList(Dlg, ID_SF_CODEPAGE, CurrentCodepage, false, false, false, false, false); break; } @@ -245,10 +245,10 @@ static intptr_t hndSaveFileAs(Dialog* Dlg, intptr_t msg, intptr_t param1, void* { if (param1 == ID_SF_OK) { - const auto CodepagePtr = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + auto& Codepage = edit_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); FarListPos pos{ sizeof(pos) }; Dlg->SendMessage(DM_LISTGETCURPOS, ID_SF_CODEPAGE, &pos); - *CodepagePtr = Dlg->GetListItemSimpleUserData(ID_SF_CODEPAGE, pos.SelectPos); + Codepage = Dlg->GetListItemSimpleUserData(ID_SF_CODEPAGE, pos.SelectPos); return TRUE; } diff --git a/far/filefilterparams.cpp b/far/filefilterparams.cpp index 4138b417e6..f026e4cdb3 100644 --- a/far/filefilterparams.cpp +++ b/far/filefilterparams.cpp @@ -645,7 +645,7 @@ static intptr_t FileFilterConfigDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1 { if (Param1 == ID_FF_BUTTON_ATTRIBUTES) { - const auto Context = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto Context = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); AttributesDialog(Context->Attributes); break; } @@ -681,7 +681,7 @@ static intptr_t FileFilterConfigDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1 { SCOPED_ACTION(Dialog::suppress_redraw)(Dlg); - const auto Context = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto Context = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); Dlg->SendMessage(DM_SETTEXTPTR,ID_FF_MASKEDIT,const_cast(L"*")); Dlg->SendMessage(DM_SETTEXTPTR,ID_FF_SIZEFROMEDIT,nullptr); Dlg->SendMessage(DM_SETTEXTPTR,ID_FF_SIZETOEDIT,nullptr); @@ -707,7 +707,7 @@ static intptr_t FileFilterConfigDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1 } else if (Param1==ID_FF_MAKETRANSPARENT) { - const auto Context = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto Context = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); for (auto& i: Context->Colors->Color) { @@ -738,7 +738,7 @@ static intptr_t FileFilterConfigDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1 if ((Msg==DN_BTNCLICK && Param1 >= ID_HER_NORMALFILE && Param1 <= ID_HER_SELECTEDCURSORMARKING) || (Msg==DN_CONTROLINPUT && Param1==ID_HER_COLOREXAMPLE && static_cast(Param2)->EventType == MOUSE_EVENT && static_cast(Param2)->Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED)) { - const auto Context = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto Context = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); if (Msg==DN_CONTROLINPUT) { @@ -760,7 +760,7 @@ static intptr_t FileFilterConfigDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1 case DM_REFRESHCOLORS: { - const auto Context = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto Context = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); const size_t Size = Dlg->SendMessage(DM_GETDLGITEM, ID_HER_COLOREXAMPLE, nullptr); const block_ptr Buffer(Size); FarGetDialogItem gdi{ sizeof(gdi), Size, Buffer.data() }; @@ -785,16 +785,16 @@ static intptr_t FileFilterConfigDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1 if (Param1 == ID_FF_OK && Dlg->SendMessage(DM_GETCHECK, ID_FF_MATCHSIZE, nullptr)) { - string Size = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ID_FF_SIZEFROMEDIT, nullptr)); + string Size = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ID_FF_SIZEFROMEDIT, nullptr)); bool Ok = Size.empty() || CheckFileSizeStringFormat(Size); if (Ok) { - Size = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ID_FF_SIZETOEDIT, nullptr)); + Size = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ID_FF_SIZETOEDIT, nullptr)); Ok = Size.empty() || CheckFileSizeStringFormat(Size); } if (!Ok) { - const auto Context = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto Context = view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); Message(MSG_WARNING, msg(Context->Colors? lng::MFileHilightTitle : lng::MFileFilterTitle), { diff --git a/far/filelist.cpp b/far/filelist.cpp index 1859291f95..8966c98857 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -5664,15 +5664,15 @@ size_t FileList::FileListToPluginItem2(const FileListItem& fi,FarGetPluginPanelI FileListItemToPluginPanelItemBasic(fi, *gpi->Item); gpi->Item->NumberOfLinks = fi.IsNumberOfLinksRead()? fi.NumberOfLinks(this) : 0; - auto data = reinterpret_cast(gpi->Item); + auto data = edit_as(gpi->Item); const auto end = data + gpi->Size; data += StaticSize; const auto CopyToBuffer = [&](string_view const Str) { - const auto Result = reinterpret_cast(data); - *copy_string(Str, reinterpret_cast(data)) = {}; + const auto Result = edit_as(data); + *copy_string(Str, Result) = {}; return Result; }; @@ -5696,7 +5696,7 @@ size_t FileList::FileListToPluginItem2(const FileListItem& fi,FarGetPluginPanelI { if (not_enough_for(ColumnsSize)) return size; - gpi->Item->CustomColumnData = reinterpret_cast(data); + gpi->Item->CustomColumnData = view_as(data); data += ColumnsSize; } diff --git a/far/filetype.cpp b/far/filetype.cpp index 6cb77d28ad..4d4a384418 100644 --- a/far/filetype.cpp +++ b/far/filetype.cpp @@ -372,7 +372,7 @@ static intptr_t EditTypeRecordDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,v if (Param1==ETR_BUTTON_OK) { - return filemasks().assign(reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ETR_EDIT_MASKS, nullptr))); + return filemasks().assign(view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, ETR_EDIT_MASKS, nullptr))); } break; diff --git a/far/findfile.cpp b/far/findfile.cpp index 6621e3e5b3..70e4d369a0 100644 --- a/far/findfile.cpp +++ b/far/findfile.cpp @@ -660,7 +660,7 @@ intptr_t FindFiles::AdvancedDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, if (Param1==AD_BUTTON_OK) { - const auto Data = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, AD_EDIT_SEARCHFIRST, nullptr)); + const auto Data = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, AD_EDIT_SEARCHFIRST, nullptr)); if (Data && *Data && !CheckFileSizeStringFormat(Data)) { @@ -765,7 +765,7 @@ intptr_t FindFiles::MainDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void { case FAD_BUTTON_FIND: { - string Mask(reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, FAD_EDIT_MASK, nullptr))); + string Mask(view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, FAD_EDIT_MASK, nullptr))); if (Mask.empty()) Mask = L"*"sv; @@ -834,7 +834,7 @@ intptr_t FindFiles::MainDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void { SCOPED_ACTION(Dialog::suppress_redraw)(Dlg); - const auto Src = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, Param2 ? FAD_EDIT_TEXT : FAD_EDIT_HEX, nullptr)); + const auto Src = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, Param2 ? FAD_EDIT_TEXT : FAD_EDIT_HEX, nullptr)); const auto strDataStr = ConvertHexString(Src, CodePage, !Param2); Dlg->SendMessage(DM_SETTEXTPTR,Param2?FAD_EDIT_HEX:FAD_EDIT_TEXT, UNSAFE_CSTR(strDataStr)); const auto iParam = reinterpret_cast(Param2); @@ -1171,7 +1171,7 @@ bool background_searcher::LookForString(string_view const FileName) else { // Если поиск в UTF-16 (little endian), то используем исходный буфер - buffer = reinterpret_cast(readBufferA.data()); + buffer = edit_as(readBufferA.data()); } } else diff --git a/far/flink.cpp b/far/flink.cpp index 365e2e9dd5..943d3bf1e8 100644 --- a/far/flink.cpp +++ b/far/flink.cpp @@ -364,7 +364,7 @@ bool GetReparsePointInfo(string_view const Object, string& DestBuffer, LPDWORD R WCHAR StringList[1]; }; - const auto& AppExecLinkReparseBuffer = *static_cast(static_cast(&rdb->GenericReparseBuffer)); + const auto& AppExecLinkReparseBuffer = view_as(&rdb->GenericReparseBuffer); if (AppExecLinkReparseBuffer.StringCount <= FilenameIndex) return false; @@ -921,7 +921,7 @@ TEST_CASE("flink.fill.reparse.buffer") REQUIRE(Buffer->MountPointReparseBuffer.PrintNameOffset == 30); REQUIRE(Buffer->MountPointReparseBuffer.PrintNameLength == 20); - REQUIRE(std::equal(ALL_CONST_RANGE(ExpectedData), static_cast(static_cast(Buffer.data())))); + REQUIRE(std::equal(ALL_CONST_RANGE(ExpectedData), view_as(Buffer.data()))); } { @@ -963,7 +963,7 @@ TEST_CASE("flink.fill.reparse.buffer") REQUIRE(Buffer->SymbolicLinkReparseBuffer.PrintNameLength == 20); REQUIRE(Buffer->SymbolicLinkReparseBuffer.Flags == 0); - REQUIRE(std::equal(ALL_CONST_RANGE(ExpectedData), static_cast(static_cast(Buffer.data())))); + REQUIRE(std::equal(ALL_CONST_RANGE(ExpectedData), view_as(Buffer.data()))); } } diff --git a/far/hotplug.cpp b/far/hotplug.cpp index 858a061dee..9043361692 100644 --- a/far/hotplug.cpp +++ b/far/hotplug.cpp @@ -207,7 +207,7 @@ static bool GetDeviceProperty(DEVINST hDevInst, DWORD Property, DWORD& Value) { return GetDevicePropertyImpl(hDevInst, [&](const dev_info& Info, SP_DEVINFO_DATA& DeviceInfoData) { - return Info.GetDeviceRegistryProperty(DeviceInfoData, Property, nullptr, reinterpret_cast(&Value), sizeof(Value), nullptr); + return Info.GetDeviceRegistryProperty(DeviceInfoData, Property, nullptr, edit_as(&Value), sizeof(Value), nullptr); }); } @@ -219,7 +219,7 @@ static bool GetDeviceProperty(DEVINST hDevInst, DWORD Property, string& Value) return os::detail::ApiDynamicStringReceiver(Value, [&](span Buffer) { DWORD RequiredSize = 0; - if (Info.GetDeviceRegistryProperty(DeviceInfoData, Property, nullptr, reinterpret_cast(Buffer.data()), static_cast(Buffer.size()), &RequiredSize)) + if (Info.GetDeviceRegistryProperty(DeviceInfoData, Property, nullptr, edit_as(Buffer.data()), static_cast(Buffer.size()), &RequiredSize)) return RequiredSize / sizeof(wchar_t) - 1; return RequiredSize / sizeof(wchar_t); }); diff --git a/far/infolist.cpp b/far/infolist.cpp index 4691ab257d..fe53f30524 100644 --- a/far/infolist.cpp +++ b/far/infolist.cpp @@ -220,7 +220,7 @@ void InfoList::DisplayObject() PrintInfo(strComputerName); os::netapi::ptr ServerInfo; - if (NetServerGetInfo(nullptr, 101, reinterpret_cast(&ptr_setter(ServerInfo))) == NERR_Success) + if (NetServerGetInfo(nullptr, 101, edit_as(*&ptr_setter(ServerInfo))) == NERR_Success) { if(ServerInfo->sv101_comment && *ServerInfo->sv101_comment) { @@ -246,7 +246,7 @@ void InfoList::DisplayObject() PrintInfo(DisplayName); os::netapi::ptr UserInfo; - if (UserNameRead && NetUserGetInfo(nullptr, UserLogonName.c_str(), 1, reinterpret_cast(&ptr_setter(UserInfo))) == NERR_Success) + if (UserNameRead && NetUserGetInfo(nullptr, UserLogonName.c_str(), 1, edit_as(&ptr_setter(UserInfo))) == NERR_Success) { if(UserInfo->usri1_comment && *UserInfo->usri1_comment) { diff --git a/far/macro.cpp b/far/macro.cpp index 036dc84848..3151b1685f 100644 --- a/far/macro.cpp +++ b/far/macro.cpp @@ -925,7 +925,9 @@ bool KeyMacro::AddMacro(const UUID& PluginId, const MacroAddMacroV1* Data) if (Data->Flags & KMFLAGS_NOSENDKEYSTOPLUGINS) Flags |= MFLAGS_NOSENDKEYSTOPLUGINS; intptr_t Priority = 50; - if (Data->StructSize >= sizeof(MacroAddMacro)) Priority = reinterpret_cast(Data)->Priority; + if (Data->StructSize >= sizeof(MacroAddMacro)) + Priority = view_as(Data)->Priority; + FarMacroValue values[] { static_cast(Data->Area), @@ -1134,13 +1136,13 @@ intptr_t KeyMacro::ParamMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo if (Param1==MS_BUTTON_OK) { - const auto Sequence = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, MS_EDIT_SEQUENCE, nullptr)); + const auto Sequence = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, MS_EDIT_SEQUENCE, nullptr)); if (*Sequence) { if (ParseMacroString(Sequence,KMFLAGS_LUA,true)) { m_RecCode=Sequence; - m_RecDescription = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, MS_EDIT_DESCR, nullptr)); + m_RecDescription = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, MS_EDIT_DESCR, nullptr)); return TRUE; } } @@ -1734,7 +1736,7 @@ void KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data) api.PassValue(0); return IsStringType? - api.PassValue(reinterpret_cast(ActualWindow->VMProcess(CheckCode))) : + api.PassValue(view_as(ActualWindow->VMProcess(CheckCode))) : api.PassValue(ActualWindow->VMProcess(CheckCode)); } @@ -1982,7 +1984,7 @@ void KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data) if (CheckCode == MCODE_V_MENUINFOID && CurrentWindow && CurrentWindow->GetType() == windowtype_menu) { - return api.PassValue(reinterpret_cast(CurrentWindow->VMProcess(MCODE_V_DLGINFOID))); + return api.PassValue(view_as(CurrentWindow->VMProcess(MCODE_V_DLGINFOID))); } if (IsMenuArea(CurArea) || CurArea == MACROAREA_DIALOG) @@ -2002,7 +2004,7 @@ void KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data) break; case MCODE_V_MENUINFOID: - return api.PassValue(reinterpret_cast(CurrentWindow->VMProcess(CheckCode))); + return api.PassValue(view_as(CurrentWindow->VMProcess(CheckCode))); } } } @@ -2958,7 +2960,7 @@ void FarMacroApi::msgBoxFunc() const Flags|=FMSG_MB_OK; const auto TempBuf = concat(title, L'\n', text); - const auto Result = pluginapi::apiMessageFn(&FarUuid, &FarUuid, Flags, nullptr, reinterpret_cast(TempBuf.c_str()), 0, 0) + 1; + const auto Result = pluginapi::apiMessageFn(&FarUuid, &FarUuid, Flags, nullptr, view_as(TempBuf.c_str()), 0, 0) + 1; PassValue(Result); } diff --git a/far/main.cpp b/far/main.cpp index c596072be8..c9e1a7b9d6 100644 --- a/far/main.cpp +++ b/far/main.cpp @@ -506,7 +506,7 @@ static void log_hook_wow64_status() { if (const auto LdrLoadDll = GetProcAddress(NtDll, "LdrLoadDll")) { - const auto FunctionData = reinterpret_cast(LdrLoadDll); + const auto FunctionData = view_as(LdrLoadDll); LOGWARNING(L"LdrLoadDll: {}"sv, BlobToHexString({ FunctionData, 32 })); } } diff --git a/far/memcheck.cpp b/far/memcheck.cpp index db2188cc1a..d5a43f7f88 100644 --- a/far/memcheck.cpp +++ b/far/memcheck.cpp @@ -80,7 +80,7 @@ struct MEMINFO int& end_marker() { - return *reinterpret_cast(reinterpret_cast(this) + Size - sizeof(EndMarker)); + return *edit_as(this, Size - sizeof(EndMarker)); } }; @@ -89,12 +89,12 @@ static MEMINFO* LastMemBlock = &FirstMemBlock; static auto to_real(void* address, std::align_val_t Alignment) { - return static_cast(static_cast(static_cast(address) - aligned_size(sizeof(MEMINFO), static_cast(Alignment)))); + return edit_as(address, 0 - aligned_size(sizeof(MEMINFO), static_cast(Alignment))); } static void* to_user(MEMINFO* address) { - return static_cast(static_cast(address)) + address->HeaderSize; + return edit_as(address, address->HeaderSize); } static void check_chain() diff --git a/far/message.cpp b/far/message.cpp index f2f9c1922a..e7c99e0650 100644 --- a/far/message.cpp +++ b/far/message.cpp @@ -162,7 +162,7 @@ intptr_t message_context::DlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* case KEY_CTRLNUMPAD0: case KEY_RCTRLNUMPAD0: { - SetClipboardText(*reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr))); + SetClipboardText(*view_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr))); } break; } diff --git a/far/panel.cpp b/far/panel.cpp index 44e43d6123..f015ae719e 100644 --- a/far/panel.cpp +++ b/far/panel.cpp @@ -739,9 +739,9 @@ int Panel::SetPluginCommand(int Command,int Param1,void* Param2) { dirInfo->StructSize = sizeof(*dirInfo); dirInfo->PluginId = Info.PluginUuid; - dirInfo->Name = static_cast(static_cast(static_cast(Param2) + folderOffset)); - dirInfo->Param = static_cast(static_cast(static_cast(Param2) + pluginDataOffset)); - dirInfo->File = static_cast(static_cast(static_cast(Param2) + pluginFileOffset)); + dirInfo->Name = view_as(Param2, folderOffset); + dirInfo->Param = view_as(Param2, pluginDataOffset); + dirInfo->File = view_as(Param2, pluginFileOffset); *copy_string(Info.ShortcutFolder, const_cast(dirInfo->Name)) = {}; *copy_string(Info.PluginData, const_cast(dirInfo->Param)) = {}; *copy_string(Info.PluginFile, const_cast(dirInfo->File)) = {}; diff --git a/far/platform.cpp b/far/platform.cpp index 23e03ced4c..eba3085ce6 100644 --- a/far/platform.cpp +++ b/far/platform.cpp @@ -158,7 +158,7 @@ static string format_error_impl(unsigned const ErrorCode, bool const Nt) (Nt? GetModuleHandle(L"ntdll.dll") : nullptr), ErrorCode, 0, - reinterpret_cast(&ptr_setter(Buffer)), + edit_as(&ptr_setter(Buffer)), 0, nullptr); @@ -272,7 +272,7 @@ bool get_locale_value(LCID const LcId, LCTYPE const Id, string& Value) bool get_locale_value(LCID const LcId, LCTYPE const Id, int& Value) { - return GetLocaleInfo(LcId, Id | LOCALE_RETURN_NUMBER, reinterpret_cast(&Value), sizeof(Value) / sizeof(wchar_t)) != 0; + return GetLocaleInfo(LcId, Id | LOCALE_RETURN_NUMBER, edit_as(&Value), sizeof(Value) / sizeof(wchar_t)) != 0; } string GetPrivateProfileString(string_view const AppName, string_view const KeyName, string_view const Default, string_view const FileName) diff --git a/far/platform.fs.cpp b/far/platform.fs.cpp index 9c626db15d..7312e72c2a 100644 --- a/far/platform.fs.cpp +++ b/far/platform.fs.cpp @@ -336,7 +336,7 @@ namespace os::fs else { FindData.FileId = 0; - CopyNames(reinterpret_cast(DirectoryInfo)); + CopyNames(view_as(&DirectoryInfo)); } } @@ -431,7 +431,7 @@ namespace os::fs if (!QueryResult) return nullptr; - const auto DirectoryInfo = reinterpret_cast(Handle->BufferBase.data()); + const auto DirectoryInfo = view_as(Handle->BufferBase.data()); DirectoryInfoToFindData(*DirectoryInfo, FindData, Handle->Extended); fill_allocation_size_alternative(FindData, Directory); Handle->NextOffset = DirectoryInfo->NextEntryOffset; @@ -443,10 +443,10 @@ namespace os::fs bool Result = false; auto& Handle = *static_cast(Find.native_handle()); bool Status = true, set_errcode = true; - auto DirectoryInfo = reinterpret_cast(Handle.BufferBase.data()); + auto DirectoryInfo = view_as(Handle.BufferBase.data()); if (Handle.NextOffset) { - DirectoryInfo = reinterpret_cast(reinterpret_cast(DirectoryInfo) + Handle.NextOffset); + DirectoryInfo = view_as(DirectoryInfo, Handle.NextOffset); } else { @@ -459,7 +459,7 @@ namespace os::fs if (Handle.Buffer2) { Handle.BufferBase = std::move(Handle.Buffer2); - DirectoryInfo = reinterpret_cast(Handle.BufferBase.data()); + DirectoryInfo = view_as(Handle.BufferBase.data()); } else { @@ -621,8 +621,8 @@ namespace os::fs BufferSize *= 2; Handle->BufferBase.reset(BufferSize); // sometimes for directories NtQueryInformationFile returns STATUS_SUCCESS but doesn't fill the buffer - const auto StreamInfo = reinterpret_cast(Handle->BufferBase.data()); - StreamInfo->StreamNameLength = 0; + auto& StreamInfo = edit_as(Handle->BufferBase.data()); + StreamInfo.StreamNameLength = 0; // BUGBUG check result (void)Handle->Object.NtQueryInformationFile(Handle->BufferBase.data(), Handle->BufferBase.size(), FileStreamInformation, &Result); } @@ -631,11 +631,11 @@ namespace os::fs if (Result != STATUS_SUCCESS) return nullptr; - const auto StreamInfo = reinterpret_cast(Handle->BufferBase.data()); - Handle->NextOffset = StreamInfo->NextEntryOffset; + const auto& StreamInfo = view_as(Handle->BufferBase.data()); + Handle->NextOffset = StreamInfo.NextEntryOffset; const auto StreamData = static_cast(FindStreamData); - if (!FileStreamInformationToFindStreamData(*StreamInfo, *StreamData)) + if (!FileStreamInformationToFindStreamData(StreamInfo, *StreamData)) return nullptr; return find_file_handle(Handle.release()); @@ -653,7 +653,7 @@ namespace os::fs if (!Handle->NextOffset) return false; - const auto StreamInfo = reinterpret_cast(Handle->BufferBase.data() + Handle->NextOffset); + const auto StreamInfo = view_as(Handle->BufferBase.data() + Handle->NextOffset); Handle->NextOffset = StreamInfo->NextEntryOffset? Handle->NextOffset + StreamInfo->NextEntryOffset : 0; const auto StreamData = static_cast(FindStreamData); diff --git a/far/platform.reg.cpp b/far/platform.reg.cpp index bc4d2022ab..ffd37a6a3a 100644 --- a/far/platform.reg.cpp +++ b/far/platform.reg.cpp @@ -158,7 +158,7 @@ namespace os::reg if (!query_value(native_handle(), Name, Type, Buffer) || !is_string_type(Type)) return false; - Value.assign(reinterpret_cast(Buffer.data()), Buffer.size() / sizeof(wchar_t)); + Value.assign(view_as(Buffer.data()), Buffer.size() / sizeof(wchar_t)); if (ends_with(Value, L'\0')) { Value.pop_back(); diff --git a/far/platform.version.cpp b/far/platform.version.cpp index 5a844538c0..a73ca33ce4 100644 --- a/far/platform.version.cpp +++ b/far/platform.version.cpp @@ -154,7 +154,7 @@ namespace os::version static bool get_os_version(OSVERSIONINFOEX& Info) { - const auto InfoPtr = static_cast(static_cast(&Info)); + const auto InfoPtr = edit_as(&Info); if (imports.RtlGetVersion && imports.RtlGetVersion(InfoPtr) == STATUS_SUCCESS) return true; diff --git a/far/plist.cpp b/far/plist.cpp index 9085d3e379..cd98e9fd7d 100644 --- a/far/plist.cpp +++ b/far/plist.cpp @@ -119,7 +119,7 @@ static bool is_alttab_window(HWND const Window) static BOOL CALLBACK EnumWindowsProc(HWND const Window, LPARAM const Param) { - auto& Info = *reinterpret_cast(Param); + auto& Info = edit_as(Param); return cpp_try( [&] diff --git a/far/plugapi.cpp b/far/plugapi.cpp index 2e191c9720..09423ffe73 100644 --- a/far/plugapi.cpp +++ b/far/plugapi.cpp @@ -400,14 +400,14 @@ BOOL WINAPI apiShowHelp(const wchar_t *ModuleName, const wchar_t *HelpTopic, FAR } else if (ModuleName && (Flags&FHELP_GUID)) { - if (!*ModuleName || *reinterpret_cast(ModuleName) == FarUuid) + if (!*ModuleName || view_as(ModuleName) == FarUuid) { OFlags |= FHELP_FARHELP; strTopic = HelpTopic + ((*HelpTopic == L':') ? 1 : 0); } else { - if (const auto plugin = Global->CtrlObject->Plugins->FindPlugin(*reinterpret_cast(ModuleName))) + if (const auto plugin = Global->CtrlObject->Plugins->FindPlugin(view_as(ModuleName))) { OFlags |= FHELP_CUSTOMPATH; strTopic = help::make_link(ExtractFilePath(plugin->ModuleName()), HelpTopic); @@ -1248,7 +1248,7 @@ intptr_t WINAPI apiMessageFn(const UUID* PluginId, const UUID* Id, unsigned long if (Flags & FMSG_ALLINONE) { std::vector Strings; - for (const auto& i: enum_tokens(reinterpret_cast(Items), L"\n"sv)) + for (const auto& i: enum_tokens(view_as(Items), L"\n"sv)) { Strings.emplace_back(i); } @@ -1574,7 +1574,7 @@ namespace magic template static auto CastRawDataToVector(span const RawItems) { - auto Items = reinterpret_cast*>(RawItems.data()[RawItems.size()].Reserved[0]); + const auto Items = edit_as*>(RawItems.data()[RawItems.size()].Reserved[0]); Items->pop_back(); // not needed anymore return std::unique_ptr>(Items); } @@ -2614,7 +2614,7 @@ intptr_t WINAPI apiMacroControl(const UUID* PluginId, FAR_MACRO_CONTROL_COMMANDS Result->StructSize = sizeof(MacroParseResult); Result->ErrCode = ErrCode; Result->ErrPos = { static_cast(ErrPos.x), static_cast(ErrPos.y) }; - Result->ErrSrc = reinterpret_cast(static_cast(Param2) + stringOffset); + Result->ErrSrc = view_as(Param2, stringOffset); *copy_string(ErrSrc, const_cast(Result->ErrSrc)) = {}; } diff --git a/far/plugins.cpp b/far/plugins.cpp index 72f235a44d..f10e45ab35 100644 --- a/far/plugins.cpp +++ b/far/plugins.cpp @@ -1690,12 +1690,13 @@ static char* BufReserve(char*& Buf, size_t Count, size_t& Rest, size_t& Size) static wchar_t* StrToBuf(const string& Str, char*& Buf, size_t& Rest, size_t& Size) { const auto Count = (Str.size() + 1) * sizeof(wchar_t); - const auto Res = reinterpret_cast(BufReserve(Buf, Count, Rest, Size)); - if (Res) - { - *copy_string(Str, Res) = {}; - } - return Res; + const auto BufPtr = BufReserve(Buf, Count, Rest, Size); + if (!BufPtr) + return {}; + + const auto StrPtr = edit_as(BufPtr); + *copy_string(Str, StrPtr) = {}; + return StrPtr; } @@ -1707,8 +1708,8 @@ static void ItemsToBuf(PluginMenuItem& Menu, const std::vector& NamesArr if (Menu.Count) { - const auto Items = reinterpret_cast(BufReserve(Buf, Menu.Count * sizeof(wchar_t*), Rest, Size)); - const auto Uuids = reinterpret_cast(BufReserve(Buf, Menu.Count * sizeof(UUID), Rest, Size)); + const auto Items = edit_as(BufReserve(Buf, Menu.Count * sizeof(wchar_t*), Rest, Size)); + const auto Uuids = edit_as(BufReserve(Buf, Menu.Count * sizeof(UUID), Rest, Size)); Menu.Strings = Items; Menu.Guids = Uuids; @@ -1795,15 +1796,15 @@ size_t PluginManager::GetPluginInformation(Plugin* pPlugin, FarGetPluginInformat if (pInfo) { Rest = BufferSize - Size; - Buffer = reinterpret_cast(pInfo) + Size; + Buffer = edit_as(pInfo, Size); } else { pInfo = &Temp.fgpi; } - pInfo->PInfo = reinterpret_cast(pInfo+1); - pInfo->GInfo = reinterpret_cast(pInfo->PInfo+1); + pInfo->PInfo = edit_as(pInfo + 1); + pInfo->GInfo = edit_as(pInfo->PInfo + 1); pInfo->ModuleName = StrToBuf(pPlugin->ModuleName(), Buffer, Rest, Size); pInfo->Flags = 0; diff --git a/far/print.cpp b/far/print.cpp index a7079eea14..129cae7c93 100644 --- a/far/print.cpp +++ b/far/print.cpp @@ -123,7 +123,7 @@ void PrintFiles(FileList* SrcPanel) PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr, 4, - static_cast(static_cast(pi.data())), + edit_as(pi.data()), static_cast(pi.size()), &Needed, &PrintersCount @@ -257,7 +257,7 @@ void PrintFiles(FileList* SrcPanel) DOC_INFO_1 di1{ UNSAFE_CSTR(FileName) }; - if (!StartDocPrinter(Printer.native_handle(), 1, reinterpret_cast(&di1))) + if (!StartDocPrinter(Printer.native_handle(), 1, edit_as(&di1))) throw MAKE_FAR_EXCEPTION(L"StartDocPrinter error"sv); SCOPE_EXIT{ EndDocPrinter(Printer.native_handle()); }; diff --git a/far/setattr.cpp b/far/setattr.cpp index 00eff5e0c9..ecc53f4e82 100644 --- a/far/setattr.cpp +++ b/far/setattr.cpp @@ -323,7 +323,7 @@ static void AdvancedAttributesDialog(SetAttrDlgParam* const DlgParam) static intptr_t SetAttrDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2) { - const auto DlgParam = reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto DlgParam = edit_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); switch (Msg) { @@ -513,7 +513,7 @@ static intptr_t SetAttrDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Pa if (locale.date_format() != date_type::ymd) break; - if (reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, Param1, nullptr))[0] != L' ') + if (view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, Param1, nullptr))[0] != L' ') break; SCOPED_ACTION(Dialog::suppress_redraw)(Dlg); @@ -914,9 +914,9 @@ static bool ShellSetFileAttributesImpl(Panel* SrcPanel, const string* Object) { const auto path = path::join(SrcPanel->GetCurDir(), SingleSelFileName); os::netapi::ptr DfsInfo; - auto Result = imports.NetDfsGetInfo(UNSAFE_CSTR(path), nullptr, nullptr, 3, reinterpret_cast(&ptr_setter(DfsInfo))); + auto Result = imports.NetDfsGetInfo(UNSAFE_CSTR(path), nullptr, nullptr, 3, edit_as(&ptr_setter(DfsInfo))); if (Result != NERR_Success) - Result = imports.NetDfsGetClientInfo(UNSAFE_CSTR(path), nullptr, nullptr, 3, reinterpret_cast(&ptr_setter(DfsInfo))); + Result = imports.NetDfsGetClientInfo(UNSAFE_CSTR(path), nullptr, nullptr, 3, edit_as(&ptr_setter(DfsInfo))); if (Result == NERR_Success) { KnownReparsePoint = true; diff --git a/far/setcolor.cpp b/far/setcolor.cpp index 6f40cf405b..d46ba98a43 100644 --- a/far/setcolor.cpp +++ b/far/setcolor.cpp @@ -557,7 +557,7 @@ constexpr auto static intptr_t GetColorDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void* Param2) { - auto& ColorState = *reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + auto& ColorState = edit_as(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); auto& CurColor = ColorState.CurColor; const auto GetColor = [Param1](size_t const Offset) diff --git a/far/stddlg.cpp b/far/stddlg.cpp index f6eb656797..a16522fd82 100644 --- a/far/stddlg.cpp +++ b/far/stddlg.cpp @@ -991,7 +991,7 @@ void single_progress::update(size_t const Percent) const { m_Dialog->SendMessage(DM_SETTEXTPTR, single_progress_detail::items::pr_progress, UNSAFE_CSTR(make_progressbar(single_progress_detail::DlgW - 10, Percent, true, true))); - const auto Title = reinterpret_cast(m_Dialog->SendMessage(DM_GETCONSTTEXTPTR, single_progress_detail::items::pr_doublebox, {})); + const auto Title = view_as(m_Dialog->SendMessage(DM_GETCONSTTEXTPTR, single_progress_detail::items::pr_doublebox, {})); m_Dialog->SendMessage(DM_SETTEXTPTR, single_progress_detail::items::pr_console_title, UNSAFE_CSTR(concat(L'{', str(Percent), L"%} "sv, Title))); } diff --git a/far/string_sort.hpp b/far/string_sort.hpp index 67f993035e..b4bc964da5 100644 --- a/far/string_sort.hpp +++ b/far/string_sort.hpp @@ -62,6 +62,8 @@ namespace string_sort struct [[nodiscard]] less_t { + using is_transparent = void; + [[nodiscard]] bool operator()(string_view Str1, string_view Str2) const { diff --git a/far/usermenu.cpp b/far/usermenu.cpp index 4a95370117..d6295ac4b4 100644 --- a/far/usermenu.cpp +++ b/far/usermenu.cpp @@ -902,8 +902,8 @@ intptr_t UserMenu::EditMenuDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, v if (Param1==EM_BUTTON_OK) { bool Result = true; - const string_view HotKey = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, EM_HOTKEY_EDIT, nullptr)); - const string_view Label = reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, EM_LABEL_EDIT, nullptr)); + const string_view HotKey = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, EM_HOTKEY_EDIT, nullptr)); + const string_view Label = view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, EM_LABEL_EDIT, nullptr)); int FocusPos=-1; if (HotKey != L"--"sv) diff --git a/far/vbuild.m4 b/far/vbuild.m4 index ac6a89d7ec..af1f7458a7 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -5931 +5932 diff --git a/far/viewer.cpp b/far/viewer.cpp index 5a8848c959..d638456717 100644 --- a/far/viewer.cpp +++ b/far/viewer.cpp @@ -439,7 +439,7 @@ bool Viewer::isBinaryFile(uintptr_t cp) // very approximate: looks for '\0' in f if (IsUnicodeCodePage(cp)) { - return contains(span(reinterpret_cast(Buffer), BytesRead / sizeof(wchar_t)), L'\0'); + return contains(span(view_as(Buffer), BytesRead / sizeof(wchar_t)), L'\0'); } else { @@ -708,7 +708,7 @@ int Viewer::txt_dump(std::string_view const Str, size_t ClientWidth, string& Out if (IsUnicodeCodePage(m_Codepage)) { - OutStr.assign(reinterpret_cast(Str.data()), Str.size() / sizeof(wchar_t)); + OutStr.assign(view_as(Str.data()), Str.size() / sizeof(wchar_t)); if (m_Codepage == CP_REVERSEBOM) { swap_bytes(OutStr.data(), OutStr.data(), OutStr.size() * sizeof(wchar_t)); @@ -2492,16 +2492,16 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo { if (SD_EDIT_TEXT == Param1 || SD_EDIT_HEX == Param1) { - const auto Data = reinterpret_cast(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); - Data->hex_mode = (SD_EDIT_HEX == Param1); + auto& Data = edit_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); + Data.hex_mode = (SD_EDIT_HEX == Param1); } break; } case DN_BTNCLICK: { bool need_focus = false; - const auto Data = reinterpret_cast(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); - const auto cradio = (Data->hex_mode ? SD_RADIO_HEX : SD_RADIO_TEXT); + auto& Data = edit_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); + const auto cradio = (Data.hex_mode? SD_RADIO_HEX : SD_RADIO_TEXT); if ((Param1 == SD_RADIO_TEXT || Param1 == SD_RADIO_HEX) && Param2) { @@ -2519,7 +2519,7 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo Dlg->SendMessage(DM_GETEDITPOSITION, sd_src, &esp); FarDialogItemData item{ sizeof(item) }; Dlg->SendMessage(DM_GETTEXT, sd_src, &item); - const string Src(reinterpret_cast(Dlg->SendMessage(DM_GETCONSTTEXTPTR, sd_src, nullptr)), item.PtrLength); + const string Src(view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, sd_src, nullptr)), item.PtrLength); const auto strTo = ConvertHexString(Src, m_Codepage, !new_hex); item.PtrLength = strTo.size(); item.PtrData = UNSAFE_CSTR(strTo); @@ -2542,17 +2542,17 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo Dlg->SendMessage(DM_EDITUNCHANGEDFLAG, sd_dst, ToPtr(changed)); } - Data->hex_mode = new_hex; - if (!Data->edit_autofocus) + Data.hex_mode = new_hex; + if (!Data.edit_autofocus) return TRUE; } } else if (Param1 == SD_CHECKBOX_REGEXP) { - Dlg->SendMessage(DM_SDSETVISIBILITY, Data->hex_mode, nullptr); + Dlg->SendMessage(DM_SDSETVISIBILITY, Data.hex_mode, nullptr); } - if (Data->edit_autofocus && !Data->recursive) + if (Data.edit_autofocus && !Data.recursive) { if ( need_focus || Param1 == SD_CHECKBOX_CASE @@ -2560,9 +2560,9 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo || Param1 == SD_CHECKBOX_REVERSE || Param1 == SD_CHECKBOX_REGEXP ){ - Data->recursive = true; - Dlg->SendMessage(DM_SETFOCUS, Data->hex_mode? SD_EDIT_HEX : SD_EDIT_TEXT, nullptr); - Data->recursive = false; + Data.recursive = true; + Dlg->SendMessage(DM_SETFOCUS, Data.hex_mode? SD_EDIT_HEX : SD_EDIT_TEXT, nullptr); + Data.recursive = false; } } @@ -2575,7 +2575,7 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo { if (Param1==SD_TEXT_SEARCH) { - const auto Data = reinterpret_cast(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); + const auto Data = view_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); Dlg->SendMessage(DM_SETFOCUS, (Data->hex_mode? SD_EDIT_HEX : SD_EDIT_TEXT), nullptr); return FALSE; } @@ -2583,7 +2583,7 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo } case DN_DRAWDIALOGDONE: { - if (const auto FirstChar = reinterpret_cast(Dlg->SendMessage(DM_SETDLGDATA, 0, nullptr))) + if (const auto FirstChar = view_as(Dlg->SendMessage(DM_SETDLGDATA, 0, nullptr))) Global->WindowManager->CallbackWindow([Dlg, FirstChar]() { Dlg->ProcessKey(*FirstChar); }); break; } @@ -2638,7 +2638,7 @@ constexpr auto SEARCHER_RESULT Viewer::search_hex_forward(search_data* sd) { - const auto buff = reinterpret_cast(Search_buffer.data()); + const auto buff = edit_as(Search_buffer.data()); const auto bsize = static_cast(Search_buffer.size() * sizeof(wchar_t)), slen = sd->search_len; long long to; const auto cpos = sd->CurPos; @@ -2706,7 +2706,7 @@ SEARCHER_RESULT Viewer::search_hex_forward(search_data* sd) SEARCHER_RESULT Viewer::search_hex_backward(search_data* sd) { - const auto buff = reinterpret_cast(Search_buffer.data()); + const auto buff = edit_as(Search_buffer.data()); const auto bsize = static_cast(Search_buffer.size() * sizeof(wchar_t)), slen = sd->search_len; long long to, cpos = sd->CurPos; const auto swrap = ViOpt.SearchWrapStop; diff --git a/far/wm_listener.cpp b/far/wm_listener.cpp index 24ab12c9c7..28412a5e96 100644 --- a/far/wm_listener.cpp +++ b/far/wm_listener.cpp @@ -77,11 +77,11 @@ static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lPara case DBT_DEVICEARRIVAL: case DBT_DEVICEREMOVECOMPLETE: { - const auto& BroadcastHeader = *reinterpret_cast(lParam); + const auto& BroadcastHeader = *view_as(lParam); if (BroadcastHeader.dbch_devicetype == DBT_DEVTYP_VOLUME) { LOGINFO(L"WM_DEVICECHANGE(DBT_DEVTYP_VOLUME)"sv); - const auto& BroadcastVolume = *reinterpret_cast(&BroadcastHeader); + const auto& BroadcastVolume = *view_as(&BroadcastHeader); message_manager::instance().notify(update_devices, update_devices_message { BroadcastVolume.dbcv_unitmask, @@ -98,7 +98,7 @@ static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lPara case WM_SETTINGCHANGE: if (lParam) { - const auto Area = reinterpret_cast(lParam); + const auto Area = view_as(lParam); if (Area == L"Environment"sv) {