From 0213eaf76155be6c164052d7b460bd10753a3cbe Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 22 Feb 2018 01:45:16 +1100 Subject: [PATCH] Silence MSVC C4996 in specific cases --- src/desktop/version.cpp | 10 ++++++++++ src/network_asio.cpp | 10 ++++++++++ src/wesnothd_connection.cpp | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/desktop/version.cpp b/src/desktop/version.cpp index 325f622465a4..7a19291ba318 100644 --- a/src/desktop/version.cpp +++ b/src/desktop/version.cpp @@ -197,11 +197,21 @@ std::string os_version() OSVERSIONINFOEX v { sizeof(OSVERSIONINFOEX) }; +#ifdef _MSC_VER +// GetVersionEx is rather problematic, but it works for our usecase. +// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx +// for more info. +#pragma warning(push) +#pragma warning(disable:4996) +#endif if(!GetVersionEx(reinterpret_cast(&v))) { ERR_DU << "os_version: GetVersionEx error (" << GetLastError() << ")\n"; return base; } +#ifdef _MSC_VER +#pragma warning(pop) +#endif const DWORD vnum = v.dwMajorVersion * 100 + v.dwMinorVersion; std::string version; diff --git a/src/network_asio.cpp b/src/network_asio.cpp index e35c33228028..b1ad9794a5e1 100644 --- a/src/network_asio.cpp +++ b/src/network_asio.cpp @@ -134,7 +134,17 @@ void connection::cancel() { if(socket_.is_open()) { boost::system::error_code ec; + +#ifdef _MSC_VER +// Silence warning about boost::asio::basic_socket::cancel always +// returning an error on XP, which we don't support anymore. +#pragma warning(push) +#pragma warning(disable:4996) +#endif socket_.cancel(ec); +#ifdef _MSC_VER +#pragma warning(pop) +#endif if(ec) { WRN_NW << "Failed to cancel network operations: " << ec.message() << std::endl; diff --git a/src/wesnothd_connection.cpp b/src/wesnothd_connection.cpp index e81af8ed850a..7cd73df72e0b 100644 --- a/src/wesnothd_connection.cpp +++ b/src/wesnothd_connection.cpp @@ -187,7 +187,17 @@ void wesnothd_connection::cancel() MPTEST_LOG; if(socket_.is_open()) { boost::system::error_code ec; + +#ifdef _MSC_VER +// Silence warning about boost::asio::basic_socket::cancel always +// returning an error on XP, which we don't support anymore. +#pragma warning(push) +#pragma warning(disable:4996) +#endif socket_.cancel(ec); +#ifdef _MSC_VER +#pragma warning(pop) +#endif if(ec) { WRN_NW << "Failed to cancel network operations: " << ec.message() << std::endl;