Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
coverity warnings
  • Loading branch information
alabuzhev committed Feb 20, 2017
1 parent 534b103 commit d43935f
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 151 deletions.
12 changes: 8 additions & 4 deletions far/FarDlgBuilder.cpp
Expand Up @@ -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():
Expand Down Expand Up @@ -686,9 +690,9 @@ void DialogBuilder::AddOKCancel(lng OKMessageId, lng CancelMessageId)
base::AddOKCancel(static_cast<int>(OKMessageId), static_cast<int>(CancelMessageId));
}

void DialogBuilder::AddOKCancel(lng OKMessageId, lng ExtraMessageId, lng CancelMessageId)
void DialogBuilder::AddButtons(range<const lng*> Buttons, size_t OkIndex, size_t CancelIndex)
{
base::AddOKCancel(static_cast<int>(OKMessageId), static_cast<int>(ExtraMessageId), static_cast<int>(CancelMessageId));
base::AddButtons(static_cast<int>(Buttons.size()), reinterpret_cast<const int*>(Buttons.data()), static_cast<int>(OkIndex), static_cast<int>(CancelIndex));
}

void DialogBuilder::AddOK()
Expand Down
2 changes: 1 addition & 1 deletion far/FarDlgBuilder.hpp
Expand Up @@ -189,7 +189,7 @@ class DialogBuilder: noncopyable, public DialogBuilderBase<DialogItemEx>

void AddOKCancel();
void AddOKCancel(lng OKMessageId, lng CancelMessageId);
void AddOKCancel(lng OKMessageId, lng ExtraMessageId, lng CancelMessageId);
void AddButtons(range<const lng*> Buttons, size_t OkIndex, size_t CancelIndex);
void AddOK();

void SetDialogMode(DWORD Flags);
Expand Down
4 changes: 4 additions & 0 deletions 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. Рефакторинг, переименования.
Expand Down
2 changes: 1 addition & 1 deletion far/cmdline.cpp
Expand Up @@ -1160,7 +1160,7 @@ bool CommandLine::ProcessOSCommands(const string& CmdLine, const std::function<v

ConsoleActivatior(false);

if (CmdLine.size() > 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 };

Expand Down
31 changes: 13 additions & 18 deletions far/codepage_selection.cpp
Expand Up @@ -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<UINT> used_cps;
std::unordered_set<uintptr_t> used_cps;
for(const auto& str_cp: split<std::vector<string>>(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")
Expand Down Expand Up @@ -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);
Expand All @@ -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<UINT>::max())
{
auto curr = std::find(ALL_CONST_RANGE(m_F8CpOrder), static_cast<UINT>(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<UINT>(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);
}
2 changes: 1 addition & 1 deletion far/codepage_selection.hpp
Expand Up @@ -121,7 +121,7 @@ class F8CP
private:
string m_AcpName, m_OemName, m_UtfName;
mutable string m_Number;
std::vector<UINT> m_F8CpOrder;
std::vector<uintptr_t> m_F8CpOrder;
};

#endif // CODEPAGE_SELECTION_HPP_AD209CF7_F280_4E6D_83A7_F0601E4EBB71
4 changes: 3 additions & 1 deletion far/config.cpp
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions far/copy.cpp
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down
100 changes: 55 additions & 45 deletions far/delete.cpp
Expand Up @@ -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<int> CharDist(0, 255);
std::mt19937 mt(clock()); // std::random_device doesn't work in w2k
std::uniform_int_distribution<int> CharDist(0, 255);

bool BufInit = false;
auto BufInit = false;

do
do
{
static std::array<BYTE, BufSize> Buf;
if (!BufInit)
{
if (Global->Opt->WipeSymbol == -1)
{
static std::array<BYTE, BufSize> 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)
Expand Down
6 changes: 3 additions & 3 deletions far/dlgedit.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion far/dlgedit.hpp
Expand Up @@ -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;
Expand Down
24 changes: 16 additions & 8 deletions far/farwinapi.cpp
Expand Up @@ -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<int>(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);
Expand Down Expand Up @@ -1920,28 +1931,25 @@ 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
{
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
{
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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions far/farwinapi.hpp
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions far/filelist.cpp
Expand Up @@ -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':';
Expand Down

0 comments on commit d43935f

Please sign in to comment.