Skip to content

Commit

Permalink
Silence MSVC C4996 in specific cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 21, 2018
1 parent 8707a13 commit 0213eaf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/desktop/version.cpp
Expand Up @@ -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<OSVERSIONINFO*>(&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;
Expand Down
10 changes: 10 additions & 0 deletions src/network_asio.cpp
Expand Up @@ -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<Protocol>::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;
Expand Down
10 changes: 10 additions & 0 deletions src/wesnothd_connection.cpp
Expand Up @@ -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<Protocol>::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;
Expand Down

0 comments on commit 0213eaf

Please sign in to comment.