From a850639a8732220d35f9432d9fbcbb745187e8d5 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Tue, 3 Jan 2017 20:51:29 -0600 Subject: [PATCH] Fix various MSVC 2015 /W3 warnings * The compiler doesn't like implicit conversions to bool. (it emits a "performance warning") * It also doesn't like an unused argument in an exception catch block. --- src/agent/Agent.cc | 14 +++++++------- src/agent/ConsoleInput.cc | 14 +++++++------- src/agent/Scraper.cc | 4 ++-- src/libwinpty/winpty.cc | 6 +++--- src/shared/GenRandom.cc | 9 +++++---- src/shared/WindowsVersion.cc | 2 +- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/agent/Agent.cc b/src/agent/Agent.cc index 748c540a..4dbcb6d3 100644 --- a/src/agent/Agent.cc +++ b/src/agent/Agent.cc @@ -147,8 +147,8 @@ Agent::Agent(LPCWSTR controlPipeName, int mouseMode, int initialCols, int initialRows) : - m_useConerr(agentFlags & WINPTY_FLAG_CONERR), - m_plainMode(agentFlags & WINPTY_FLAG_PLAIN_OUTPUT), + m_useConerr((agentFlags & WINPTY_FLAG_CONERR) != 0), + m_plainMode((agentFlags & WINPTY_FLAG_PLAIN_OUTPUT) != 0), m_mouseMode(mouseMode) { trace("Agent::Agent entered"); @@ -310,7 +310,7 @@ void Agent::pollControlPipe() ReadBuffer buffer(std::move(packetData)); buffer.getRawValue(); // Discard the size. handlePacket(buffer); - } catch (const ReadBuffer::DecodeError &error) { + } catch (const ReadBuffer::DecodeError&) { ASSERT(false && "Decode error"); } } @@ -349,8 +349,8 @@ void Agent::handleStartProcessPacket(ReadBuffer &packet) ASSERT(!m_closingOutputPipes); const uint64_t spawnFlags = packet.getInt64(); - const bool wantProcessHandle = packet.getInt32(); - const bool wantThreadHandle = packet.getInt32(); + const bool wantProcessHandle = packet.getInt32() != 0; + const bool wantThreadHandle = packet.getInt32() != 0; const auto program = packet.getWString(); const auto cmdline = packet.getWString(); const auto cwd = packet.getWString(); @@ -403,8 +403,8 @@ void Agent::handleStartProcessPacket(ReadBuffer &packet) } CloseHandle(pi.hThread); m_childProcess = pi.hProcess; - m_autoShutdown = (spawnFlags & WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN); - m_exitAfterShutdown = (spawnFlags & WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN); + m_autoShutdown = (spawnFlags & WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN) != 0; + m_exitAfterShutdown = (spawnFlags & WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN) != 0; reply.putInt32(static_cast(StartProcessResult::ProcessCreated)); reply.putInt64(replyProcess); reply.putInt64(replyThread); diff --git a/src/agent/ConsoleInput.cc b/src/agent/ConsoleInput.cc index aac16244..6ee6dc69 100644 --- a/src/agent/ConsoleInput.cc +++ b/src/agent/ConsoleInput.cc @@ -288,10 +288,10 @@ void ConsoleInput::flushIncompleteEscapeCode() void ConsoleInput::updateInputFlags(bool forceTrace) { const DWORD mode = inputConsoleMode(); - const bool newFlagEE = mode & ENABLE_EXTENDED_FLAGS; - const bool newFlagMI = mode & ENABLE_MOUSE_INPUT; - const bool newFlagQE = mode & ENABLE_QUICK_EDIT_MODE; - const bool newFlagEI = mode & 0x200; + const bool newFlagEE = (mode & ENABLE_EXTENDED_FLAGS) != 0; + const bool newFlagMI = (mode & ENABLE_MOUSE_INPUT) != 0; + const bool newFlagQE = (mode & ENABLE_QUICK_EDIT_MODE) != 0; + const bool newFlagEI = (mode & 0x200) != 0; if (forceTrace || newFlagEE != m_enableExtendedEnabled || newFlagMI != m_mouseInputEnabled || @@ -591,9 +591,9 @@ void ConsoleInput::appendKeyPress(std::vector &records, uint32_t codePoint, uint16_t keyState) { - const bool ctrl = keyState & LEFT_CTRL_PRESSED; - const bool alt = keyState & LEFT_ALT_PRESSED; - const bool shift = keyState & SHIFT_PRESSED; + const bool ctrl = (keyState & LEFT_CTRL_PRESSED) != 0; + const bool alt = (keyState & LEFT_ALT_PRESSED) != 0; + const bool shift = (keyState & SHIFT_PRESSED) != 0; if (isTracingEnabled()) { static bool debugInput = hasDebugFlag("input"); diff --git a/src/agent/Scraper.cc b/src/agent/Scraper.cc index c2a5d5e3..844ad56a 100755 --- a/src/agent/Scraper.cc +++ b/src/agent/Scraper.cc @@ -330,12 +330,12 @@ void Scraper::syncConsoleContentAndSize( } const ConsoleScreenBufferInfo info = m_consoleBuffer->bufferInfo(); - BOOL cursorVisible = true; + bool cursorVisible = true; CONSOLE_CURSOR_INFO cursorInfo = {}; if (!GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo)) { trace("GetConsoleCursorInfo failed"); } else { - cursorVisible = cursorInfo.bVisible; + cursorVisible = cursorInfo.bVisible != 0; } // If an app resizes the buffer height, then we enter "direct mode", where diff --git a/src/libwinpty/winpty.cc b/src/libwinpty/winpty.cc index e6d4efa6..e89e3481 100644 --- a/src/libwinpty/winpty.cc +++ b/src/libwinpty/winpty.cc @@ -108,7 +108,7 @@ static void translateException(winpty_error_ptr_t *&err) { try { try { throw; - } catch (const ReadBuffer::DecodeError &e) { + } catch (const ReadBuffer::DecodeError&) { ret = const_cast(&kBadRpcPacket); } catch (const LibWinptyException &e) { std::unique_ptr obj(new winpty_error_t); @@ -125,7 +125,7 @@ static void translateException(winpty_error_ptr_t *&err) { obj->msgDynamic = new std::shared_ptr(msg); ret = obj.release(); } - } catch (const std::bad_alloc &e) { + } catch (const std::bad_alloc&) { ret = const_cast(&kOutOfMemory); } catch (...) { ret = const_cast(&kUncaughtException); @@ -703,7 +703,7 @@ WINPTY_API HANDLE winpty_agent_process(winpty_t *wp) { static const wchar_t *cstrFromWStringOrNull(const std::wstring &str) { try { return str.c_str(); - } catch (const std::bad_alloc &e) { + } catch (const std::bad_alloc&) { return nullptr; } } diff --git a/src/shared/GenRandom.cc b/src/shared/GenRandom.cc index 930bd8c4..6d792064 100644 --- a/src/shared/GenRandom.cc +++ b/src/shared/GenRandom.cc @@ -50,7 +50,7 @@ GenRandom::GenRandom() : m_advapi32(L"advapi32.dll") { // Fall back to the crypto API. m_cryptProvIsValid = CryptAcquireContext(&m_cryptProv, nullptr, nullptr, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); + PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) != 0; if (!m_cryptProvIsValid) { trace("GenRandom: CryptAcquireContext failed: %u", static_cast(GetLastError())); @@ -68,14 +68,15 @@ bool GenRandom::fillBuffer(void *buffer, size_t size) { memset(buffer, 0, size); bool success = false; if (m_rtlGenRandom != nullptr) { - success = m_rtlGenRandom(buffer, size); + success = m_rtlGenRandom(buffer, size) != 0; if (!success) { trace("GenRandom: RtlGenRandom/SystemFunction036 failed: %u", static_cast(GetLastError())); } } else if (m_cryptProvIsValid) { - success = CryptGenRandom(m_cryptProv, size, - reinterpret_cast(buffer)); + success = + CryptGenRandom(m_cryptProv, size, + reinterpret_cast(buffer)) != 0; if (!success) { trace("GenRandom: CryptGenRandom failed, size=%d, lasterror=%u", static_cast(size), diff --git a/src/shared/WindowsVersion.cc b/src/shared/WindowsVersion.cc index c82c89e8..d89b00d8 100644 --- a/src/shared/WindowsVersion.cc +++ b/src/shared/WindowsVersion.cc @@ -232,7 +232,7 @@ void dumpWindowsVersion() { fb << "F:" << versionToString(fileVersionFromInfo(info)) << '/' << "P:" << versionToString(productVersionFromInfo(info)); return fb.str_moved(); - } catch (const ModuleNotFound &e) { + } catch (const ModuleNotFound&) { return utf8FromWide(dllPath) + ":none"; } catch (const WinptyException &e) { trace("Error getting %s version: %s",