[PowerRename] Use int type instead of long in PowerRename Settings (#2502)

* Fix signed/unsigned comparison in power rename Settings.

* Use int instead of long (same on 64-bit windows).
This commit is contained in:
vldmr11080 2020-05-01 13:26:38 +02:00 committed by GitHub
parent 8908bd9889
commit 64df515c63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 24 deletions

View File

@ -29,7 +29,7 @@ namespace
const wchar_t c_mruList[] = L"MRUList"; const wchar_t c_mruList[] = L"MRUList";
const wchar_t c_insertionIdx[] = L"InsertionIdx"; const wchar_t c_insertionIdx[] = L"InsertionIdx";
long GetRegNumber(const std::wstring& valueName, long defaultValue) unsigned int GetRegNumber(const std::wstring& valueName, unsigned int defaultValue)
{ {
DWORD type = REG_DWORD; DWORD type = REG_DWORD;
DWORD data = 0; DWORD data = 0;
@ -41,7 +41,7 @@ namespace
return defaultValue; return defaultValue;
} }
void SetRegNumber(const std::wstring& valueName, long value) void SetRegNumber(const std::wstring& valueName, unsigned int value)
{ {
SHSetValue(HKEY_CURRENT_USER, c_rootRegPath, valueName.c_str(), REG_DWORD, &value, sizeof(value)); SHSetValue(HKEY_CURRENT_USER, c_rootRegPath, valueName.c_str(), REG_DWORD, &value, sizeof(value));
} }
@ -86,7 +86,7 @@ namespace
class MRUListHandler class MRUListHandler
{ {
public: public:
MRUListHandler(int size, const std::wstring& filePath, const std::wstring& regPath) : MRUListHandler(unsigned int size, const std::wstring& filePath, const std::wstring& regPath) :
pushIdx(0), pushIdx(0),
nextIdx(1), nextIdx(1),
size(size), size(size),
@ -112,9 +112,9 @@ private:
bool Exists(const std::wstring& data); bool Exists(const std::wstring& data);
std::vector<std::wstring> items; std::vector<std::wstring> items;
long pushIdx; unsigned int pushIdx;
long nextIdx; unsigned int nextIdx;
long size; unsigned int size;
const std::wstring jsonFilePath; const std::wstring jsonFilePath;
const std::wstring registryFilePath; const std::wstring registryFilePath;
}; };
@ -140,7 +140,7 @@ bool MRUListHandler::Next(std::wstring& data)
return false; return false;
} }
// Go backwards to consume latest items first. // Go backwards to consume latest items first.
long idx = (pushIdx + size - nextIdx) % size; unsigned int idx = (pushIdx + size - nextIdx) % size;
if (items[idx].empty()) if (items[idx].empty())
{ {
Reset(); Reset();
@ -212,15 +212,15 @@ void MRUListHandler::ParseJson()
const json::JsonObject& jsonObject = json.value(); const json::JsonObject& jsonObject = json.value();
try try
{ {
long oldSize{ size }; unsigned int oldSize{ size };
if (json::has(jsonObject, c_maxMRUSize, json::JsonValueType::Number)) if (json::has(jsonObject, c_maxMRUSize, json::JsonValueType::Number))
{ {
oldSize = (long)jsonObject.GetNamedNumber(c_maxMRUSize); oldSize = (unsigned int)jsonObject.GetNamedNumber(c_maxMRUSize);
} }
long oldPushIdx{ 0 }; unsigned int oldPushIdx{ 0 };
if (json::has(jsonObject, c_insertionIdx, json::JsonValueType::Number)) if (json::has(jsonObject, c_insertionIdx, json::JsonValueType::Number))
{ {
oldPushIdx = (long)jsonObject.GetNamedNumber(c_insertionIdx); oldPushIdx = (unsigned int)jsonObject.GetNamedNumber(c_insertionIdx);
if (oldPushIdx < 0 || oldPushIdx >= oldSize) if (oldPushIdx < 0 || oldPushIdx >= oldSize)
{ {
oldPushIdx = 0; oldPushIdx = 0;
@ -240,7 +240,7 @@ void MRUListHandler::ParseJson()
else else
{ {
std::vector<std::wstring> temp; std::vector<std::wstring> temp;
for (uint32_t i = 0; i < min(jsonArray.Size(), size); ++i) for (unsigned int i = 0; i < min(jsonArray.Size(), size); ++i)
{ {
int idx = (oldPushIdx + oldSize - (i + 1)) % oldSize; int idx = (oldPushIdx + oldSize - (i + 1)) % oldSize;
temp.push_back(std::wstring(jsonArray.GetStringAt(idx))); temp.push_back(std::wstring(jsonArray.GetStringAt(idx)));
@ -248,7 +248,7 @@ void MRUListHandler::ParseJson()
if (size > oldSize) if (size > oldSize)
{ {
std::reverse(std::begin(temp), std::end(temp)); std::reverse(std::begin(temp), std::end(temp));
pushIdx = (long)temp.size(); pushIdx = (unsigned int)temp.size();
temp.resize(size); temp.resize(size);
} }
else else
@ -295,7 +295,7 @@ private:
CRenameMRU(int size, const std::wstring& filePath, const std::wstring& regPath); CRenameMRU(int size, const std::wstring& filePath, const std::wstring& regPath);
std::unique_ptr<MRUListHandler> mruList; std::unique_ptr<MRUListHandler> mruList;
long refCount = 0; unsigned int refCount = 0;
}; };
CRenameMRU::CRenameMRU(int size, const std::wstring& filePath, const std::wstring& regPath) : CRenameMRU::CRenameMRU(int size, const std::wstring& filePath, const std::wstring& regPath) :
@ -307,7 +307,7 @@ CRenameMRU::CRenameMRU(int size, const std::wstring& filePath, const std::wstrin
HRESULT CRenameMRU::CreateInstance(_In_ const std::wstring& filePath, _In_ const std::wstring& regPath, _Outptr_ IUnknown** ppUnk) HRESULT CRenameMRU::CreateInstance(_In_ const std::wstring& filePath, _In_ const std::wstring& regPath, _Outptr_ IUnknown** ppUnk)
{ {
*ppUnk = nullptr; *ppUnk = nullptr;
long maxMRUSize = CSettingsInstance().GetMaxMRUSize(); unsigned int maxMRUSize = CSettingsInstance().GetMaxMRUSize();
HRESULT hr = maxMRUSize > 0 ? S_OK : E_FAIL; HRESULT hr = maxMRUSize > 0 ? S_OK : E_FAIL;
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -330,7 +330,7 @@ IFACEMETHODIMP_(ULONG) CRenameMRU::AddRef()
IFACEMETHODIMP_(ULONG) CRenameMRU::Release() IFACEMETHODIMP_(ULONG) CRenameMRU::Release()
{ {
long cnt = InterlockedDecrement(&refCount); unsigned int cnt = InterlockedDecrement(&refCount);
if (cnt == 0) if (cnt == 0)
{ {
@ -485,11 +485,11 @@ void CSettings::ParseJson()
} }
if (json::has(jsonSettings, c_maxMRUSize, json::JsonValueType::Number)) if (json::has(jsonSettings, c_maxMRUSize, json::JsonValueType::Number))
{ {
settings.maxMRUSize = (long)jsonSettings.GetNamedNumber(c_maxMRUSize); settings.maxMRUSize = (unsigned int)jsonSettings.GetNamedNumber(c_maxMRUSize);
} }
if (json::has(jsonSettings, c_flags, json::JsonValueType::Number)) if (json::has(jsonSettings, c_flags, json::JsonValueType::Number))
{ {
settings.flags = (long)jsonSettings.GetNamedNumber(c_flags); settings.flags = (unsigned int)jsonSettings.GetNamedNumber(c_flags);
} }
if (json::has(jsonSettings, c_searchText, json::JsonValueType::String)) if (json::has(jsonSettings, c_searchText, json::JsonValueType::String))
{ {

View File

@ -61,22 +61,22 @@ public:
settings.MRUEnabled = MRUEnabled; settings.MRUEnabled = MRUEnabled;
} }
inline long GetMaxMRUSize() const inline unsigned int GetMaxMRUSize() const
{ {
return settings.maxMRUSize; return settings.maxMRUSize;
} }
inline void SetMaxMRUSize(long maxMRUSize) inline void SetMaxMRUSize(unsigned int maxMRUSize)
{ {
settings.maxMRUSize = maxMRUSize; settings.maxMRUSize = maxMRUSize;
} }
inline long GetFlags() const inline unsigned int GetFlags() const
{ {
return settings.flags; return settings.flags;
} }
inline void SetFlags(long flags) inline void SetFlags(unsigned int flags)
{ {
settings.flags = flags; settings.flags = flags;
Save(); Save();
@ -115,8 +115,8 @@ private:
bool extendedContextMenuOnly{ false }; // Disabled by default. bool extendedContextMenuOnly{ false }; // Disabled by default.
bool persistState{ true }; bool persistState{ true };
bool MRUEnabled{ true }; bool MRUEnabled{ true };
long maxMRUSize{ 10 }; unsigned int maxMRUSize{ 10 };
long flags{ 0 }; unsigned int flags{ 0 };
std::wstring searchText{}; std::wstring searchText{};
std::wstring replaceText{}; std::wstring replaceText{};
}; };