Skip to content

Commit

Permalink
Merge pull request #454 from GermanAizek/patch
Browse files Browse the repository at this point in the history
Code refactor, use Win64 GlobalMemoryStatusEx and  fixed CWE-190
  • Loading branch information
alabuzhev authored Oct 9, 2021
2 parents e41f053 + a08cfe0 commit 6edbccc
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion far/preservestyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ bool PreserveStyleReplaceString(
--LastItem;
while (((j != LastItem) || (j == LastItem && T < j->Token.size())) && Source[Idx])
{
bool Sep = (static_cast<size_t>(I) < Idx && static_cast<size_t>(I + 1) != Source.size() && IsPreserveStyleTokenSeparator(Source[Idx])
bool Sep = (static_cast<size_t>(I) < Idx && static_cast<size_t>(I) + 1 != Source.size() && IsPreserveStyleTokenSeparator(Source[Idx])
&& !IsPreserveStyleTokenSeparator(Source[Idx-1])
&& !IsPreserveStyleTokenSeparator(Source[Idx+1]));

Expand Down
1 change: 0 additions & 1 deletion plugins/arclite/SimpleXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class View : public str_view
mutable str_view saved;

public:
~View() noexcept {}
View(const char *_Beg, const char *_End) noexcept : str_view(_Beg, _End), saved(_Beg) {}

void save_start(const int offset = 0) const noexcept { saved.ps = ps + offset; }
Expand Down
2 changes: 1 addition & 1 deletion plugins/arclite/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Error {
: code(E_MESSAGE), file(__FILE__), line(__LINE__)
{
std::string message(std::string(typeid(e).name()) + ": " + e.what());
messages.push_back(std::wstring(message.begin(), message.end()));
messages.emplace_back(message.begin(), message.end());
}

void SetResults(std::list<std::wstring>&& errs, std::list<std::wstring>&& wrns) {
Expand Down
6 changes: 3 additions & 3 deletions plugins/arclite/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class FileWriteCache {
std::shared_ptr<ExtractProgress> progress;

size_t get_max_cache_size() const {
MEMORYSTATUS mem_st;
GlobalMemoryStatus(&mem_st);
size_t size = mem_st.dwAvailPhys;
MEMORYSTATUSEX mem_st{sizeof(mem_st)};
GlobalMemoryStatusEx(&mem_st);
auto size = static_cast<size_t>(mem_st.ullAvailPhys);
if (size < c_min_cache_size)
size = c_min_cache_size;
if (size > c_max_cache_size)
Expand Down
2 changes: 1 addition & 1 deletion plugins/arclite/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Plugin {
new_dir.clear();

archive->find_dir(new_dir);
current_dir = new_dir;
current_dir = std::move(new_dir);
}

void list(PluginPanelItem** panel_items, size_t* items_number) {
Expand Down
5 changes: 3 additions & 2 deletions plugins/arclite/sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class SfxOptionsDialog: public Far::Dialog {
for (unsigned i = 0; i < profiles.size(); i++) {
profile_names.push_back(profiles[i].name);
}
profile_names.push_back(std::wstring());
profile_names.emplace_back();
profile_ctrl_id = combo_box(profile_names, profiles.size(), 30, DIF_DROPDOWNLIST);
new_line();
separator();
Expand All @@ -373,7 +373,7 @@ class SfxOptionsDialog: public Far::Dialog {
if (name_width < name.size())
name_width = name.size();
});
module_names.push_back(std::wstring());
module_names.emplace_back();
module_ctrl_id = combo_box(module_names, sfx_modules.find_by_name(m_options.name), name_width + 6, DIF_DROPDOWNLIST);
new_line();

Expand All @@ -386,6 +386,7 @@ class SfxOptionsDialog: public Far::Dialog {

size_t label_len = 0;
std::vector<std::wstring> labels;
labels.reserve(7);
labels.push_back(Far::get_msg(MSG_SFX_OPTIONS_DLG_VER_INFO_PRODUCT_NAME));
labels.push_back(Far::get_msg(MSG_SFX_OPTIONS_DLG_VER_INFO_VERSION));
labels.push_back(Far::get_msg(MSG_SFX_OPTIONS_DLG_VER_INFO_COMPANY_NAME));
Expand Down
2 changes: 1 addition & 1 deletion plugins/arclite/sysutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ bool Key::enum_sub_keys_nt(std::vector<std::wstring>& names) noexcept {
SetLastError(res);
return false;
}
names.push_back(std::wstring(name.data(), name_size));
names.emplace_back(name.data(), name_size);
index++;
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions plugins/arclite/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ class UpdateDialog: public Far::Dialog {
arc_path.replace(pos, ext.size(), new_ext);
set_text(arc_path_ctrl_id, arc_path);

old_ext = new_ext;
old_ext = std::move(new_ext);
return true;
}

Expand Down Expand Up @@ -1285,7 +1285,7 @@ class UpdateDialog: public Far::Dialog {
if (profile.options == m_options)
profile_idx = static_cast<unsigned>(profile_names.size()) - 1;
});
profile_names.push_back(std::wstring());
profile_names.emplace_back();
label(Far::get_msg(MSG_UPDATE_DLG_PROFILE));
profile_ctrl_id = combo_box(profile_names, profile_idx, 30, DIF_DROPDOWNLIST);
spacer(1);
Expand Down Expand Up @@ -1512,7 +1512,7 @@ class MultiSelectDialog: public Far::Dialog {
if (diff > window_ratio_diff)
break;
window_ratio_diff = diff;
prev_col_widths = col_widths;
prev_col_widths = std::move(col_widths);
}
return prev_col_widths;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/emenu/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ bool CPlugin::ShowTextMenu(HMENU hMenu, LPCONTEXTMENU pPreferredMenu, LPCONTEXTM
//if (szLeft.Len() > szRight.Len())
//szSub = szLeft;
//else
szSub = szRight;
szSub = std::move(szRight);
}
}

Expand Down
7 changes: 5 additions & 2 deletions plugins/network/NetClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ NetBrowser::NetBrowser()


NetBrowser::~NetBrowser()
{
#ifdef NETWORK_LOGGING
{
CloseLogfile();
#endif
}
#else
= default;
#endif


#ifdef NETWORK_LOGGING

Expand Down
2 changes: 1 addition & 1 deletion plugins/network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ HANDLE WINAPI OpenW(const OpenInfo *Info)

if (Info->OpenFrom==OPEN_COMMANDLINE)
{
wchar_t Path[MAX_PATH] = L"\\\\";
int I=0;
auto cmd=const_cast<wchar_t*>(reinterpret_cast<OpenCommandLineInfo*>(Info->Data)->CommandLine); //BUGBUG
wchar_t *p=wcschr(cmd, L':');
Expand Down Expand Up @@ -70,6 +69,7 @@ HANDLE WINAPI OpenW(const OpenInfo *Info)
I=2;
}

wchar_t Path[MAX_PATH] = L"\\\\";
lstrcpy(Path+I, cmd);
FSF.Unquote(Path);
// Expanding environment variables.
Expand Down

0 comments on commit 6edbccc

Please sign in to comment.