diff --git a/far/FarDlgBuilder.cpp b/far/FarDlgBuilder.cpp index 814374e8be..cbd0415fd6 100644 --- a/far/FarDlgBuilder.cpp +++ b/far/FarDlgBuilder.cpp @@ -234,9 +234,13 @@ static bool IsEditField(DialogItemEx *Item) */ DialogBuilder::DialogBuilder(lng TitleMessageId, const wchar_t *HelpTopic, Dialog::dialog_handler handler): - m_HelpTopic(NullToEmpty(HelpTopic)), m_Mode(0), m_IdExist(false), m_handler(handler) + m_HelpTopic(NullToEmpty(HelpTopic)), + m_Mode(0), + m_Id(GUID_NULL), + m_IdExist(false), + m_handler(handler) { - AddBorder(DialogBuilder::GetLangString(TitleMessageId)); + AddBorder(GetLangString(TitleMessageId)); } DialogBuilder::DialogBuilder(): @@ -686,9 +690,9 @@ void DialogBuilder::AddOKCancel(lng OKMessageId, lng CancelMessageId) base::AddOKCancel(static_cast(OKMessageId), static_cast(CancelMessageId)); } -void DialogBuilder::AddOKCancel(lng OKMessageId, lng ExtraMessageId, lng CancelMessageId) +void DialogBuilder::AddButtons(range Buttons, size_t OkIndex, size_t CancelIndex) { - base::AddOKCancel(static_cast(OKMessageId), static_cast(ExtraMessageId), static_cast(CancelMessageId)); + base::AddButtons(static_cast(Buttons.size()), reinterpret_cast(Buttons.data()), static_cast(OkIndex), static_cast(CancelIndex)); } void DialogBuilder::AddOK() diff --git a/far/FarDlgBuilder.hpp b/far/FarDlgBuilder.hpp index ca1d2db083..755e1f4346 100644 --- a/far/FarDlgBuilder.hpp +++ b/far/FarDlgBuilder.hpp @@ -189,7 +189,7 @@ class DialogBuilder: noncopyable, public DialogBuilderBase void AddOKCancel(); void AddOKCancel(lng OKMessageId, lng CancelMessageId); - void AddOKCancel(lng OKMessageId, lng ExtraMessageId, lng CancelMessageId); + void AddButtons(range Buttons, size_t OkIndex, size_t CancelIndex); void AddOK(); void SetDialogMode(DWORD Flags); diff --git a/far/changelog b/far/changelog index 9841663872..443f264727 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,7 @@ +drkns 20.02.2017 19:16:22 +0000 - build 4900 + +1. Coverity warnings. + drkns 18.02.2017 19:05:09 +0000 - build 4899 1. Рефакторинг, переименования. diff --git a/far/cmdline.cpp b/far/cmdline.cpp index 568924655d..9c5f5c98ce 100644 --- a/far/cmdline.cpp +++ b/far/cmdline.cpp @@ -1160,7 +1160,7 @@ bool CommandLine::ProcessOSCommands(const string& CmdLine, const std::function 1 && CmdLine[1] == L':' && (CmdLine.size() == 2 || !CmdLine.find_first_not_of(L' ', 2))) + if (CmdLine.size() > 1 && CmdLine[1] == L':' && (CmdLine.size() == 2 || CmdLine.find_first_not_of(L' ', 2) == string::npos)) { wchar_t NewDir[] = { Upper(CmdLine[0]), L':', 0, 0 }; diff --git a/far/codepage_selection.cpp b/far/codepage_selection.cpp index 3e422ff863..e1ac164ef7 100644 --- a/far/codepage_selection.cpp +++ b/far/codepage_selection.cpp @@ -813,17 +813,16 @@ F8CP::F8CP(bool viewer): m_OemName(MSG(Global->OnlyEditorViewerUsed? (viewer? lng::MSingleViewF8DOS : lng::MSingleEditF8DOS) : (viewer? lng::MViewF8DOS : lng::MEditF8DOS))), m_UtfName(L"UTF-8") { - - UINT defcp = viewer ? Global->Opt->ViOpt.DefaultCodePage : Global->Opt->EdOpt.DefaultCodePage; + uintptr_t defcp = viewer ? Global->Opt->ViOpt.DefaultCodePage : Global->Opt->EdOpt.DefaultCodePage; string cps(viewer ? Global->Opt->ViOpt.strF8CPs : Global->Opt->EdOpt.strF8CPs); if (cps != L"-1") { - std::unordered_set used_cps; + std::unordered_set used_cps; for(const auto& str_cp: split>(cps, 0)) { auto s = Upper(str_cp); - UINT cp = 0; + uintptr_t cp = 0; if (s == L"ANSI" || s == L"ACP" || s == L"WIN") cp = GetACP(); else if (s == L"OEM" || s == L"OEMCP" || s == L"DOS") @@ -853,7 +852,7 @@ F8CP::F8CP(bool viewer): } if (m_F8CpOrder.empty()) { - UINT acp = GetACP(), oemcp = GetOEMCP(); + const uintptr_t acp = GetACP(), oemcp = GetOEMCP(); if (cps != L"-1") defcp = acp; m_F8CpOrder.emplace_back(defcp); @@ -866,25 +865,21 @@ F8CP::F8CP(bool viewer): uintptr_t F8CP::NextCP(uintptr_t cp) const { - UINT next_cp = m_F8CpOrder[0]; - if (cp <= std::numeric_limits::max()) - { - auto curr = std::find(ALL_CONST_RANGE(m_F8CpOrder), static_cast(cp)); - if (curr != m_F8CpOrder.cend() && ++curr != m_F8CpOrder.cend()) - next_cp = *curr; - } - return next_cp; + auto curr = std::find(ALL_CONST_RANGE(m_F8CpOrder), cp); + return curr != m_F8CpOrder.cend() && ++curr != m_F8CpOrder.cend()? *curr : *m_F8CpOrder.cbegin(); } const string& F8CP::NextCPname(uintptr_t cp) const { - UINT next_cp = static_cast(NextCP(cp)); + const auto next_cp = NextCP(cp); if (next_cp == GetACP()) return m_AcpName; - else if (next_cp == GetOEMCP()) + + if (next_cp == GetOEMCP()) return m_OemName; - else if (next_cp == CP_UTF8) + + if (next_cp == CP_UTF8) return m_UtfName; - else - return m_Number = str(next_cp); + + return m_Number = str(next_cp); } diff --git a/far/codepage_selection.hpp b/far/codepage_selection.hpp index 6154f1cacd..700df0a25e 100644 --- a/far/codepage_selection.hpp +++ b/far/codepage_selection.hpp @@ -121,7 +121,7 @@ class F8CP private: string m_AcpName, m_OemName, m_UtfName; mutable string m_Number; - std::vector m_F8CpOrder; + std::vector m_F8CpOrder; }; #endif // CODEPAGE_SELECTION_HPP_AD209CF7_F280_4E6D_83A7_F0601E4EBB71 diff --git a/far/config.cpp b/far/config.cpp index 3173ccc0c5..bc8a90e51a 100644 --- a/far/config.cpp +++ b/far/config.cpp @@ -1335,7 +1335,9 @@ struct FARConfigItem int Result = 0; if (!Value->Edit(&Builder, 40, Hex)) { - Builder.AddOKCancel(lng::MOk, lng::MReset, lng::MCancel); + static constexpr lng Buttons[] = { lng::MOk, lng::MReset, lng::MCancel }; + Builder.AddSeparator(); + Builder.AddButtons(make_range(Buttons), 0, 2); Result = Builder.ShowDialogEx(); } if(Result == 0 || Result == 1) diff --git a/far/copy.cpp b/far/copy.cpp index 4c03b38ff7..f22c2d2048 100644 --- a/far/copy.cpp +++ b/far/copy.cpp @@ -484,6 +484,13 @@ ShellCopy::ShellCopy(panel_ptr SrcPanel, // исходная панель ( SrcDriveType(), DestDriveType(), CopyBufferSize(!Global->Opt->CMOpt.BufferSize.Get()? default_copy_buffer_size : Global->Opt->CMOpt.BufferSize.Get()), + OvrMode(-1), + ReadOnlyOvrMode(-1), + ReadOnlyDelMode(-1), + SkipMode(-1), + SkipEncMode(-1), + SkipDeleteMode(-1), + SkipSecurityErrors(), SelectedFolderNameLength(), RPT(RP_EXACTCOPY), AltF10(), @@ -982,9 +989,6 @@ ShellCopy::ShellCopy(panel_ptr SrcPanel, // исходная панель ( CopySecurityCopy=m_CopySecurity; } - ReadOnlyDelMode=ReadOnlyOvrMode=OvrMode=SkipEncMode=SkipMode=SkipDeleteMode=-1; - SkipSecurityErrors = false; - if (Link) { switch (CopyDlg[ID_SC_COMBO].ListPos) diff --git a/far/delete.cpp b/far/delete.cpp index a3fccd9dab..b3c7cca8dd 100644 --- a/far/delete.cpp +++ b/far/delete.cpp @@ -224,64 +224,74 @@ static bool MoveToRecycleBinInternal(const string& Objects) static bool WipeFile(const string& Name, int TotalPercent, bool& Cancel) { - bool Result = false; - - os::SetFileAttributes(Name,FILE_ATTRIBUTE_NORMAL); + if (!os::SetFileAttributes(Name, FILE_ATTRIBUTE_NORMAL)) + return false; os::fs::file_walker WipeFile; + if (!WipeFile.Open(Name, FILE_READ_DATA | FILE_WRITE_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN)) + return false; - if(WipeFile.Open(Name, FILE_READ_DATA|FILE_WRITE_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_WRITE_THROUGH|FILE_FLAG_SEQUENTIAL_SCAN)) - { - const DWORD BufSize=65536; - if(WipeFile.InitWalk(BufSize)) - { - time_check TimeCheck(time_check::mode::immediate, GetRedrawTimeout()); + const DWORD BufSize=65536; + if (!WipeFile.InitWalk(BufSize)) + return false; + + time_check TimeCheck(time_check::mode::immediate, GetRedrawTimeout()); - std::mt19937 mt(clock()); // std::random_device doesn't work in w2k - std::uniform_int_distribution CharDist(0, 255); + std::mt19937 mt(clock()); // std::random_device doesn't work in w2k + std::uniform_int_distribution CharDist(0, 255); - bool BufInit = false; + auto BufInit = false; - do + do + { + static std::array Buf; + if (!BufInit) + { + if (Global->Opt->WipeSymbol == -1) { - static std::array Buf; - if (!BufInit) - { - if (Global->Opt->WipeSymbol == -1) - { - std::generate(ALL_RANGE(Buf), [&]{ return CharDist(mt); }); - } - else - { - Buf.fill(Global->Opt->WipeSymbol); - BufInit = true; - } - } + std::generate(ALL_RANGE(Buf), [&]{ return CharDist(mt); }); + } + else + { + Buf.fill(Global->Opt->WipeSymbol); + BufInit = true; + } + } - size_t Written; - WipeFile.Write(Buf.data(), WipeFile.GetChunkSize(), Written); - if (TimeCheck) - { - if (CheckForEscSilent() && ConfirmAbortOp()) - { - Cancel=true; - return false; - } + size_t Written; + const auto WriteSize = WipeFile.GetChunkSize(); + if (!WipeFile.Write(Buf.data(), WriteSize, Written) || Written != WriteSize) + return false; - ShellDeleteMsg(Name, DEL_WIPEPROCESS, TotalPercent, WipeFile.GetPercent()); - } + if (TimeCheck) + { + if (CheckForEscSilent() && ConfirmAbortOp()) + { + Cancel=true; + return false; } - while(WipeFile.Step()); - WipeFile.SetPointer(0,nullptr,FILE_BEGIN); - WipeFile.SetEnd(); + ShellDeleteMsg(Name, DEL_WIPEPROCESS, TotalPercent, WipeFile.GetPercent()); } - WipeFile.Close(); - string strTempName; - FarMkTempEx(strTempName,nullptr,FALSE); - Result = os::MoveFile(Name,strTempName) && os::DeleteFile(strTempName); } - return Result; + while(WipeFile.Step()); + + if (!WipeFile.SetPointer(0, nullptr, FILE_BEGIN)) + return false; + + if (!WipeFile.SetEnd()) + return false; + + WipeFile.Close(); + + string strTempName; + if (!FarMkTempEx(strTempName, nullptr, FALSE)) + return false; + + if (!os::MoveFile(Name, strTempName)) + return false;; + + return os::DeleteFile(strTempName); } static int WipeDirectory(const string& Name) diff --git a/far/dlgedit.cpp b/far/dlgedit.cpp index 2b7224f091..34dc717033 100644 --- a/far/dlgedit.cpp +++ b/far/dlgedit.cpp @@ -242,12 +242,12 @@ void DlgEdit::SetInputMask(const string& InputMask) lineEdit->SetInputMask(InputMask); } -const wchar_t* DlgEdit::GetInputMask() const +string DlgEdit::GetInputMask() const { if (Type == DLGEDIT_SINGLELINE) - return lineEdit->GetInputMask().data(); + return lineEdit->GetInputMask(); - return L""; //??? + return {}; //??? } void DlgEdit::SetEditBeyondEnd(bool Mode) diff --git a/far/dlgedit.hpp b/far/dlgedit.hpp index e43550b0f5..2a0b5103ba 100644 --- a/far/dlgedit.hpp +++ b/far/dlgedit.hpp @@ -90,7 +90,7 @@ class DlgEdit: public SimpleScreenObject int GetStrSize(int Row = -1) const; void SetInputMask(const string& InputMask); - const wchar_t* GetInputMask() const; + string GetInputMask() const; void SetOvertypeMode(bool Mode); bool GetOvertypeMode() const; diff --git a/far/farwinapi.cpp b/far/farwinapi.cpp index 8f24000bb8..8abb394665 100644 --- a/far/farwinapi.cpp +++ b/far/farwinapi.cpp @@ -1731,6 +1731,17 @@ bool DetachVirtualDisk(const string& Object, VIRTUAL_STORAGE_TYPE& VirtualStorag return Result; } +string GetLocaleValue(LCID lcid, LCTYPE id) +{ + string Result; + return ApiDynamicErrorBasedStringReceiver(ERROR_INSUFFICIENT_BUFFER, Result, [&](wchar_t* Buffer, size_t Size) + { + const auto ReturnedSize = ::GetLocaleInfo(lcid, id, Buffer, static_cast(Size)); + return ReturnedSize? ReturnedSize - 1 : 0; + })? + Result : L""s; +} + string GetPrivateProfileString(const string& AppName, const string& KeyName, const string& Default, const string& FileName) { wchar_t_ptr Buffer(NT_MAX_PATH); @@ -1920,8 +1931,7 @@ bool GetDefaultPrinter(string& Printer) throw MAKE_FAR_EXCEPTION(L"Bad value type"); string Result; - GetValue(*m_Key, m_Name.data(), Result); - return Result; + return GetValue(*m_Key, m_Name.data(), Result)? Result : L""s; } unsigned int value::GetUnsigned() const @@ -1929,9 +1939,8 @@ bool GetDefaultPrinter(string& Printer) if (m_Type != REG_DWORD) throw MAKE_FAR_EXCEPTION(L"Bad value type"); - unsigned int Result = 0; - GetValue(*m_Key, m_Name.data(), Result); - return Result; + unsigned int Result; + return GetValue(*m_Key, m_Name.data(), Result)? Result : 0; } unsigned long long value::GetUnsigned64() const @@ -1939,9 +1948,8 @@ bool GetDefaultPrinter(string& Printer) if (m_Type != REG_QWORD) throw MAKE_FAR_EXCEPTION(L"Bad value type"); - unsigned long long Result = 0; - GetValue(*m_Key, m_Name.data(), Result); - return Result; + unsigned long long Result; + return GetValue(*m_Key, m_Name.data(), Result)? Result : 0; } } diff --git a/far/farwinapi.hpp b/far/farwinapi.hpp index 2bd9e47eba..b0ee0bc552 100644 --- a/far/farwinapi.hpp +++ b/far/farwinapi.hpp @@ -162,6 +162,8 @@ namespace os bool SetFileEncryptionInternal(const wchar_t* Name, bool Encrypt); bool DetachVirtualDiskInternal(const string& Object, VIRTUAL_STORAGE_TYPE& VirtualStorageType); + string GetLocaleValue(LCID lcid, LCTYPE id); + namespace fs { namespace detail diff --git a/far/filelist.cpp b/far/filelist.cpp index b3251ec575..373bb1e8d2 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -5254,9 +5254,7 @@ string FileList::GetPluginPrefix() const if (!(m_CachedOpenPanelInfo.Flags & OPIF_REALNAMES)) { PluginInfo PInfo = {sizeof(PInfo)}; - m_hPlugin->plugin()->GetPluginInfo(&PInfo); - - if (PInfo.CommandPrefix && *PInfo.CommandPrefix) + if (m_hPlugin->plugin()->GetPluginInfo(&PInfo) && PInfo.CommandPrefix && *PInfo.CommandPrefix) { string Prefix = PInfo.CommandPrefix; return Prefix.substr(0, Prefix.find(L':')) + L':'; diff --git a/far/findfile.cpp b/far/findfile.cpp index f027bc92cd..88838abc9a 100644 --- a/far/findfile.cpp +++ b/far/findfile.cpp @@ -2895,26 +2895,9 @@ void FindFiles::ProcessMessage(const AddMenuData& Data) FindFiles::FindFiles(): - AnySetFindList(), - CmpCase(), - WholeWords(), - SearchInArchives(), - SearchHex(), - NotContaining(), - UseFilter(), - FindFoldersChanged(), - SearchFromChanged(), - FindPositionChanged(), - Finalized(), - PluginMode(), - SearchMode(FINDAREA_ALL), - favoriteCodePages(), - CodePage(CP_DEFAULT), - SearchInFirst(), - FindExitItem(), + itd(std::make_unique()), FileMaskForFindFile(std::make_unique()), Filter(std::make_unique(Global->CtrlObject->Cp()->ActivePanel().get(), FFT_FINDFILE)), - itd(std::make_unique()), m_TimeCheck(time_check::mode::immediate, GetRedrawTimeout()), m_MessageEvent(os::event::type::manual, os::event::state::signaled) { diff --git a/far/findfile.hpp b/far/findfile.hpp index 045b9ccffc..b1140279a9 100644 --- a/far/findfile.hpp +++ b/far/findfile.hpp @@ -110,6 +110,14 @@ class FindFiles: noncopyable } }; + std::unique_ptr itd; + os::synced_queue m_Messages; + + // BUGBUG + void Lock() { PluginCS.lock(); } + void Unlock() { PluginCS.unlock(); } + auto ScopedLock() { return make_raii_wrapper(this, &FindFiles::Lock, &FindFiles::Unlock); } + private: string &PrepareDriveNameStr(string &strSearchFromRoot) const; void AdvancedDialog(); @@ -124,24 +132,23 @@ class FindFiles: noncopyable static intptr_t AdvancedDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void* Param2); // BUGBUG - bool AnySetFindList; - bool CmpCase; - bool WholeWords; - bool SearchInArchives; - bool SearchHex; - bool NotContaining; - bool UseFilter; - - bool FindFoldersChanged; - bool SearchFromChanged; - bool FindPositionChanged; - bool Finalized; - bool PluginMode; - FINDAREA SearchMode; - int favoriteCodePages; - uintptr_t CodePage; - UINT64 SearchInFirst; - struct FindListItem* FindExitItem; + bool AnySetFindList{}; + bool CmpCase{}; + bool WholeWords{}; + bool SearchInArchives{}; + bool SearchHex{}; + bool NotContaining{}; + bool UseFilter{}; + bool FindFoldersChanged{}; + bool SearchFromChanged{}; + bool FindPositionChanged{}; + bool Finalized{}; + bool PluginMode{}; + FINDAREA SearchMode{ FINDAREA_ALL }; + int favoriteCodePages{}; + uintptr_t CodePage{ CP_DEFAULT }; + UINT64 SearchInFirst {}; + struct FindListItem* FindExitItem{}; string strFindMask; string strFindStr; std::unique_ptr FileMaskForFindFile; @@ -155,27 +162,16 @@ class FindFiles: noncopyable int m_DirCount{}; int m_LastFoundNumber{}; -public: - std::unique_ptr itd; - - os::synced_queue m_Messages; - - // BUGBUG - void Lock() { PluginCS.lock(); } - void Unlock() { PluginCS.unlock(); } - auto ScopedLock() { return make_raii_wrapper(this, &FindFiles::Lock, &FindFiles::Unlock); } - -private: os::critical_section PluginCS; time_check m_TimeCheck; // BUGBUG - class background_searcher* m_Searcher; + class background_searcher* m_Searcher{}; std::exception_ptr m_ExceptionPtr; std::stack m_LastDir; string m_LastDirName; - Dialog* m_ResultsDialogPtr; - bool m_EmptyArc; + Dialog* m_ResultsDialogPtr{}; + bool m_EmptyArc{}; os::event m_MessageEvent; }; diff --git a/far/help.cpp b/far/help.cpp index 46cf2619c8..712b305050 100644 --- a/far/help.cpp +++ b/far/help.cpp @@ -1955,6 +1955,8 @@ void Help::ReadDocumentsHelp(int TypeIndex) PtrTitle=MSG(lng::MPluginsHelpTitle); ContentsName=L"PluginContents"; break; + default: + throw MAKE_FAR_EXCEPTION(L"Unsupported index"); } AddTitle(PtrTitle); @@ -1992,6 +1994,8 @@ void Help::ReadDocumentsHelp(int TypeIndex) break; } + default: + throw MAKE_FAR_EXCEPTION(L"Unsupported index"); } // сортируем по алфавиту diff --git a/far/locale.cpp b/far/locale.cpp index 4bc7958560..987841ab65 100644 --- a/far/locale.cpp +++ b/far/locale.cpp @@ -100,17 +100,7 @@ wchar_t locale::GetThousandSeparator() string locale::GetValue(LCID lcid, LCTYPE id) { - const size_t Size = GetLocaleInfo(lcid, id, nullptr, 0); - - if (!Size) - { - // TODO: log - return {}; - } - - wchar_t_ptr Buffer(Size); - GetLocaleInfo(lcid, id, Buffer.get(), static_cast(Size)); - return { Buffer.get(), Size - 1 }; + return os::GetLocaleValue(lcid, id); } string locale::GetTimeFormat() diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 8230a5879a..f6f35b31fc 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4899)m4_dnl +m4_define(BUILD,4900)m4_dnl