From 6fa00223ad8ea4fcf1cf8b6a59bebeb8918a6f3a Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Thu, 12 Oct 2017 15:38:15 -0700 Subject: [PATCH] Enable all warnings, turn the noisy ones back off, fix the others. --- src/CMakeLists.txt | 14 ++++++++++++-- src/backoff.h | 2 +- src/connection_win.cpp | 4 ++-- src/discord_register_win.cpp | 9 ++++----- src/rpc_connection.cpp | 1 + src/serialization.h | 12 +++++++++++- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4753869..cca36e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,17 @@ if(WIN32) add_definitions(-DDISCORD_WINDOWS) set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_win.cpp discord_register_win.cpp) add_library(discord-rpc ${RPC_LIBRARY_TYPE} ${BASE_RPC_SRC}) - target_compile_options(discord-rpc PRIVATE /W4) + target_compile_options(discord-rpc PRIVATE /EHsc + /Wall + /wd4514 # unreferenced inline + /wd4625 # copy constructor deleted + /wd5026 # move constructor deleted + /wd4626 # move assignment operator deleted + /wd4710 # function not inlined + /wd4820 # structure padding + /wd4946 # reinterpret_cast used between related classes + /wd5027 # move assignment operator was implicitly defined as deleted + ) endif(WIN32) if(UNIX) @@ -88,4 +98,4 @@ install( FILES "../include/discord-rpc.h" DESTINATION "include" -) \ No newline at end of file +) diff --git a/src/backoff.h b/src/backoff.h index e26f417..9d5011c 100644 --- a/src/backoff.h +++ b/src/backoff.h @@ -20,7 +20,7 @@ struct Backoff { , maxAmount(max) , current(min) , fails(0) - , randGenerator(time(0)) + , randGenerator((uint64_t)time(0)) { } diff --git a/src/connection_win.cpp b/src/connection_win.cpp index fa80570..9790e8f 100644 --- a/src/connection_win.cpp +++ b/src/connection_win.cpp @@ -9,7 +9,7 @@ int GetProcessId() { - return ::GetCurrentProcessId(); + return (int)::GetCurrentProcessId(); } struct BaseConnectionWin : public BaseConnection { @@ -125,4 +125,4 @@ bool BaseConnection::Read(void* data, size_t length) Close(); } return false; -} \ No newline at end of file +} diff --git a/src/discord_register_win.cpp b/src/discord_register_win.cpp index 8ac5b42..8eed2f0 100644 --- a/src/discord_register_win.cpp +++ b/src/discord_register_win.cpp @@ -17,9 +17,8 @@ void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) // Update the HKEY_CURRENT_USER, because it doesn't seem to require special permissions. wchar_t exeFilePath[MAX_PATH]; - int exeLen = GetModuleFileNameExW(GetCurrentProcess(), nullptr, exeFilePath, MAX_PATH); + DWORD exeLen = GetModuleFileNameExW(GetCurrentProcess(), nullptr, exeFilePath, MAX_PATH); wchar_t openCommand[1024]; - const auto commandBufferLen = sizeof(openCommand) / sizeof(*openCommand); if (command && command[0]) { StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command); @@ -46,14 +45,14 @@ void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) } DWORD len; LSTATUS result; - len = lstrlenW(protocolDescription) + 1; + len = (DWORD)lstrlenW(protocolDescription) + 1; result = RegSetKeyValueW(key, nullptr, nullptr, REG_SZ, protocolDescription, len * sizeof(wchar_t)); if (FAILED(result)) { fprintf(stderr, "Error writing description\n"); } - len = lstrlenW(protocolDescription) + 1; + len = (DWORD)lstrlenW(protocolDescription) + 1; result = RegSetKeyValueW(key, nullptr, L"URL Protocol", REG_SZ, &urlProtocol, sizeof(wchar_t)); if (FAILED(result)) { fprintf(stderr, "Error writing description\n"); @@ -65,7 +64,7 @@ void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) fprintf(stderr, "Error writing icon\n"); } - len = lstrlenW(openCommand) + 1; + len = (DWORD)lstrlenW(openCommand) + 1; result = RegSetKeyValueW( key, L"shell\\open\\command", nullptr, REG_SZ, openCommand, len * sizeof(wchar_t)); if (FAILED(result)) { diff --git a/src/rpc_connection.cpp b/src/rpc_connection.cpp index e1e9328..b492de9 100644 --- a/src/rpc_connection.cpp +++ b/src/rpc_connection.cpp @@ -129,6 +129,7 @@ bool RpcConnection::Read(JsonDocument& message) break; case Opcode::Pong: break; + case Opcode::Handshake: default: // something bad happened lastErrorCode = (int)ErrorCode::ReadCorrupt; diff --git a/src/serialization.h b/src/serialization.h index 360bde9..8bc9fa7 100644 --- a/src/serialization.h +++ b/src/serialization.h @@ -2,10 +2,20 @@ #include +#pragma warning(push) + +#pragma warning(disable : 4061) // enum is not explicitly handled by a case label +#pragma warning(disable : 4365) // signed/unsigned mismatch +#pragma warning(disable : 4464) // relative include path contains +#pragma warning(disable : 4668) // is not defined as a preprocessor macro +#pragma warning(disable : 6313) // Incorrect operator + #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" +#pragma warning(pop) + // if only there was a standard library function for this template inline size_t StringCopy(char (&dest)[Len], const char* src) @@ -111,7 +121,7 @@ public: } } void Flush() {} - size_t GetSize() const { return current_ - buffer_; } + size_t GetSize() const { return (size_t)(current_ - buffer_); } }; using MallocAllocator = rapidjson::CrtAllocator;