diff --git a/src/Win32_Interop/Win32_CommandLine.cpp b/src/Win32_Interop/Win32_CommandLine.cpp index 89773987e78..bafcb3ecceb 100644 --- a/src/Win32_Interop/Win32_CommandLine.cpp +++ b/src/Win32_Interop/Win32_CommandLine.cpp @@ -46,7 +46,7 @@ using namespace std; ArgumentMap g_argMap; vector g_pathsAccessed; -string stripQuotes(string s) { +string stripQuotes(const string& s) { if (s.length() >= 2) { if (s.at(0) == '\'' && s.at(s.length() - 1) == '\'') { if (s.length() > 2) { @@ -199,7 +199,7 @@ typedef class BindParams : public ParamExtractor { dllfunctor_stdcall f_WSAStringToAddressA = dllfunctor_stdcall("ws2_32.dll", "WSAStringToAddressA"); - bool IsIPAddress(string address) { + bool IsIPAddress(const string& address) { SOCKADDR_IN sockaddr4; sockaddr4.sin_family = AF_INET; SOCKADDR_IN6 sockaddr6; @@ -310,7 +310,7 @@ typedef class SentinelParams : public ParamExtractor { vector params; params.push_back(argv[argStartIndex + 1]); vector subParams = subCommands[argv[argStartIndex + 1]]->Extract(argStartIndex + 1, argc, argv); - for (string p : params) { + for (string p : subParams) { transform(p.begin(), p.end(), p.begin(), ::tolower); p = stripQuotes(p); params.push_back(p); @@ -457,7 +457,7 @@ std::vector split(const std::string &s, char delim) { return elems; } -vector Tokenize(string line) { +vector Tokenize(const string& line) { vector tokens; stringstream token; @@ -467,7 +467,7 @@ vector Tokenize(string line) { return tokens; } - for (string::const_iterator sit = line.begin(); sit != line.end(); sit++) { + for (string::const_iterator sit = line.begin(); sit != line.end(); ++sit) { char c = *(sit); if (isspace(c) && token.str().length() > 0) { tokens.push_back(token.str()); @@ -508,10 +508,9 @@ vector Tokenize(string line) { return tokens; } -void ParseConfFile(string confFile, string cwd, ArgumentMap& argMap) { +void ParseConfFile(const string& confFile, const string& cwd, ArgumentMap& argMap) { ifstream config; string line; - string value; char fullConfFilePath[MAX_PATH]; if (PathIsRelativeA(confFile.c_str())) { diff --git a/src/Win32_Interop/Win32_CommandLine.h b/src/Win32_Interop/Win32_CommandLine.h index c7aed6e6bc6..414d149c560 100644 --- a/src/Win32_Interop/Win32_CommandLine.h +++ b/src/Win32_Interop/Win32_CommandLine.h @@ -36,7 +36,7 @@ using namespace std; typedef map>> ArgumentMap; extern ArgumentMap g_argMap; -void ParseConfFile(string confFile, string cwd, ArgumentMap& argMap); +void ParseConfFile(const string& confFile, const string& cwd, ArgumentMap& argMap); void ParseCommandLineArguments(int argc, char** argv); vector GetAccessPaths(); diff --git a/src/Win32_Interop/Win32_EventLog.cpp b/src/Win32_Interop/Win32_EventLog.cpp index 18565408060..513ba445356 100644 --- a/src/Win32_Interop/Win32_EventLog.cpp +++ b/src/Win32_Interop/Win32_EventLog.cpp @@ -68,7 +68,7 @@ void RedisEventLog::UninstallEventLogSource() { } // sets up the registry keys required for the EventViewer message filter -void RedisEventLog::InstallEventLogSource(string appPath) { +void RedisEventLog::InstallEventLogSource(const string& appPath) { SmartRegistryHandle eventLogKey; if (ERROR_SUCCESS != RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogPath.c_str(), eventLogKey)) { throw std::system_error(GetLastError(), system_category(), "RegOpenKey failed"); @@ -156,7 +156,7 @@ void RedisEventLog::LogMessage(LPCSTR msg, const WORD type) { } } -void RedisEventLog::LogError(string msg) { +void RedisEventLog::LogError(const string& msg) { try { if (eventLogEnabled == true) { stringstream ss; diff --git a/src/Win32_Interop/Win32_EventLog.h b/src/Win32_Interop/Win32_EventLog.h index 6cdf38e263c..96803e0a9de 100644 --- a/src/Win32_Interop/Win32_EventLog.h +++ b/src/Win32_Interop/Win32_EventLog.h @@ -30,13 +30,13 @@ typedef class RedisEventLog { public: ~RedisEventLog() {} - void InstallEventLogSource(string appPath); + void InstallEventLogSource(const string& appPath); void UninstallEventLogSource(); void SetEventLogIdentity(const char* identity); void LogMessage(LPCSTR msg, const WORD type); - void LogError(string msg); + void LogError(const string& msg); string GetEventLogIdentity(); void EnableEventLog(bool enabled); diff --git a/src/Win32_Interop/Win32_PThread.c b/src/Win32_Interop/Win32_PThread.c index 36fa426e65e..694ba0f6e23 100644 --- a/src/Win32_Interop/Win32_PThread.c +++ b/src/Win32_Interop/Win32_PThread.c @@ -92,8 +92,10 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr) { switch (WaitForSingleObject(h, INFINITE)) { case WAIT_OBJECT_0: result = 0; + break; case WAIT_ABANDONED: result = EINVAL; + break; default: result = GetLastError(); } diff --git a/src/Win32_Interop/Win32_QFork.cpp b/src/Win32_Interop/Win32_QFork.cpp index a04fadb2280..a3581118e65 100644 --- a/src/Win32_Interop/Win32_QFork.cpp +++ b/src/Win32_Interop/Win32_QFork.cpp @@ -510,7 +510,7 @@ StartupStatus QForkStartup() { if (g_IsForkedProcess) { // Child command line looks like: --QFork [QForkControlMemoryMap handle] [parent pid] - HANDLE QForkControlMemoryMapHandle = (HANDLE) strtoul(g_argMap[cQFork].at(0).at(0).c_str(), NULL, 10); + HANDLE QForkControlMemoryMapHandle = (HANDLE) strtoull(g_argMap[cQFork].at(0).at(0).c_str(), NULL, 10); DWORD PPID = strtoul(g_argMap[cQFork].at(0).at(1).c_str(), NULL, 10); return QForkChildInit(QForkControlMemoryMapHandle, PPID) ? StartupStatus::ssCHILD_EXIT : StartupStatus::ssFAILED; } else { diff --git a/src/Win32_Interop/Win32_SmartHandle.h b/src/Win32_Interop/Win32_SmartHandle.h index 19b2aa08db5..db19970ac87 100644 --- a/src/Win32_Interop/Win32_SmartHandle.h +++ b/src/Win32_Interop/Win32_SmartHandle.h @@ -56,7 +56,7 @@ typedef class SmartHandle throw std::runtime_error("invalid handle passed to constructor"); } - HANDLE Assign(HANDLE h, string errorToReport) + HANDLE Assign(HANDLE h, const string& errorToReport) { Close(); m_handle = h; @@ -65,7 +65,7 @@ typedef class SmartHandle return h; } - SmartHandle(HANDLE handle, string errorToReport) + SmartHandle(HANDLE handle, const string& errorToReport) { Close(); m_handle = handle; @@ -254,7 +254,7 @@ typedef class SmartFileMapHandle m_handle = INVALID_HANDLE_VALUE; } - HANDLE Assign(HANDLE mmFile, DWORD protectionFlags, DWORD maxSizeHigh, DWORD maxSizeLow, string errorToReport) + HANDLE Assign(HANDLE mmFile, DWORD protectionFlags, DWORD maxSizeHigh, DWORD maxSizeLow, const string& errorToReport) { Unmap(); m_handle = CreateFileMapping(mmFile, NULL, protectionFlags, maxSizeHigh, maxSizeLow, NULL); @@ -269,7 +269,7 @@ typedef class SmartFileMapHandle return m_handle; } - SmartFileMapHandle(HANDLE mmFile, DWORD protectionFlags, DWORD maxSizeHigh, DWORD maxSizeLow, string errorToReport) + SmartFileMapHandle(HANDLE mmFile, DWORD protectionFlags, DWORD maxSizeHigh, DWORD maxSizeLow, const string& errorToReport) { m_handle = CreateFileMapping(mmFile, NULL, protectionFlags, maxSizeHigh, maxSizeLow, NULL); if (Invalid()) { diff --git a/src/Win32_Interop/Win32_service.cpp b/src/Win32_Interop/Win32_service.cpp index 488538e6970..f89a7b7b833 100644 --- a/src/Win32_Interop/Win32_service.cpp +++ b/src/Win32_Interop/Win32_service.cpp @@ -115,7 +115,7 @@ typedef class ServicePipeWriter { } public: - void Write(string message) { + void Write(const string& message) { if (pipe != INVALID_HANDLE_VALUE) { DWORD bytesWritten = 0; WriteFile(pipe, message.c_str(), (DWORD)message.length(), &bytesWritten, NULL); @@ -345,7 +345,7 @@ VOID ServiceInstall(int argc, char ** argv) { SetAccessACLOnFolder(userName, folder); aceMessage << "\"" << folder.c_str() << "\" "; } - ServicePipeWriter::getInstance().Write(aceMessage.str().c_str()); + ServicePipeWriter::getInstance().Write(aceMessage.str()); ServicePipeWriter::getInstance().Write("Redis successfully installed as a service."); } diff --git a/src/Win32_Interop/Win32_variadicFunctor.cpp b/src/Win32_Interop/Win32_variadicFunctor.cpp index b6a6a7579bf..00ea91d9dc4 100644 --- a/src/Win32_Interop/Win32_variadicFunctor.cpp +++ b/src/Win32_Interop/Win32_variadicFunctor.cpp @@ -36,7 +36,7 @@ DLLMap& DLLMap::getInstance() { DLLMap::DLLMap() { }; -LPVOID DLLMap::getProcAddress(string dll, string functionName) +LPVOID DLLMap::getProcAddress(const string& dll, const string& functionName) { if (find(dll) == end()) { HMODULE mod = LoadLibraryA(dll.c_str()); diff --git a/src/Win32_Interop/Win32_variadicFunctor.h b/src/Win32_Interop/Win32_variadicFunctor.h index a40ea72186e..a9cf61da788 100644 --- a/src/Win32_Interop/Win32_variadicFunctor.h +++ b/src/Win32_Interop/Win32_variadicFunctor.h @@ -36,7 +36,7 @@ class DLLMap : map { void operator=(DLLMap const&); // Don't implement to guarantee singleton semantics public: - LPVOID getProcAddress(string dll, string functionName); + LPVOID getProcAddress(const string& dll, const string& functionName); virtual ~DLLMap(); }; @@ -44,7 +44,7 @@ class DLLMap : map { template class dllfunctor_stdcall { public: - dllfunctor_stdcall(string dll, string function) + dllfunctor_stdcall(const string& dll, const string& function) { _f = (R(__stdcall *)(T...))DLLMap::getInstance().getProcAddress(dll, function.c_str()); }