Windows, compiling : reenable warning C4996 (deprecated functions)

But set _CRT_NONSTDC_NO_WARNINGS to silence silly warnings about
ANSI C function being non-standard

Remove now deprecated GetVersion()/GetVersionEx(),except single case
where where it is really needed, in feedback plugin. Remove checks for
Windows NT.

Avoid old IPv4-only inet_aton, which generated the warning.
This commit is contained in:
Vladislav Vaintroub 2018-02-07 20:17:38 +00:00
parent d995dd2865
commit 282b652028
13 changed files with 97 additions and 181 deletions

View File

@ -146,8 +146,9 @@ IF(MSVC)
ENDIF()
#TODO: update the code and remove the disabled warnings
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /we4700 /we4311 /we4477 /we4302 /we4090")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4291 /wd4996 /we4099 /we4700 /we4311 /we4477 /we4302 /we4090")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4700 /we4311 /we4477 /we4302 /we4090")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4291 /we4099 /we4700 /we4311 /we4477 /we4302 /we4090")
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
IF(MYSQL_MAINTAINER_MODE MATCHES "ERR")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")

View File

@ -17,21 +17,6 @@
#include "m_string.h"
#ifdef __WIN__
/* Windows NT/2000 discretionary access control utility functions. */
/*
Check if the operating system is built on NT technology.
RETURN
0 Windows 95/98/Me
1 otherwise
*/
static my_bool is_nt()
{
return GetVersion() < 0x80000000;
}
/*
Auxiliary structure to store pointers to the data which we need to keep
around while SECURITY_ATTRIBUTES is in use.
@ -86,12 +71,6 @@ int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror,
PSID owner_sid;
My_security_attr *attr;
if (! is_nt())
{
*psa= 0;
return 0;
}
/*
Get SID of Everyone group. Easier to retrieve all SIDs each time
this function is called than worry about thread safety.

View File

@ -92,6 +92,9 @@ static int uname(struct utsname *buf)
{
OSVERSIONINFOEX ver;
ver.dwOSVersionInfoSize = (DWORD)sizeof(ver);
#ifdef _MSC_VER
#pragma warning (disable : 4996)
#endif
if (!GetVersionEx((OSVERSIONINFO *)&ver))
return -1;

View File

@ -701,13 +701,11 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
static struct addrinfo debug_addr_info[2];
/* Simulating ipv4 192.0.2.126 */
debug_addr= & debug_sock_addr[0];
debug_addr->sin_family= AF_INET;
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.126");
inet_pton(AF_INET,"192.0.2.126",debug_addr);
/* Simulating ipv4 192.0.2.127 */
debug_addr= & debug_sock_addr[1];
debug_addr->sin_family= AF_INET;
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.127");
inet_pton(AF_INET,"192.0.2.127",debug_addr);
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in);
@ -733,13 +731,11 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
static struct addrinfo debug_addr_info[2];
/* Simulating ipv4 192.0.2.5 */
debug_addr= & debug_sock_addr[0];
debug_addr->sin_family= AF_INET;
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.5");
inet_pton(AF_INET,"192.0.2.5",debug_addr);
/* Simulating ipv4 192.0.2.4 */
debug_addr= & debug_sock_addr[1];
debug_addr->sin_family= AF_INET;
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.4");
inet_pton(AF_INET,"192.0.2.5",debug_addr);
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in);
@ -772,47 +768,13 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
static struct addrinfo debug_addr_info[2];
/* Simulating ipv6 2001:DB8::6:7E */
debug_addr= & debug_sock_addr[0];
debug_addr->sin6_family= AF_INET6;
ip6= & debug_addr->sin6_addr;
/* inet_pton not available on Windows XP. */
ip6->s6_addr[ 0] = 0x20;
ip6->s6_addr[ 1] = 0x01;
ip6->s6_addr[ 2] = 0x0d;
ip6->s6_addr[ 3] = 0xb8;
ip6->s6_addr[ 4] = 0x00;
ip6->s6_addr[ 5] = 0x00;
ip6->s6_addr[ 6] = 0x00;
ip6->s6_addr[ 7] = 0x00;
ip6->s6_addr[ 8] = 0x00;
ip6->s6_addr[ 9] = 0x00;
ip6->s6_addr[10] = 0x00;
ip6->s6_addr[11] = 0x00;
ip6->s6_addr[12] = 0x00;
ip6->s6_addr[13] = 0x06;
ip6->s6_addr[14] = 0x00;
ip6->s6_addr[15] = 0x7e;
inet_pton(AF_INET6,"2001:DB8::6:7E",ip6);
/* Simulating ipv6 2001:DB8::6:7F */
debug_addr= & debug_sock_addr[1];
debug_addr->sin6_family= AF_INET6;
ip6= & debug_addr->sin6_addr;
ip6->s6_addr[ 0] = 0x20;
ip6->s6_addr[ 1] = 0x01;
ip6->s6_addr[ 2] = 0x0d;
ip6->s6_addr[ 3] = 0xb8;
ip6->s6_addr[ 4] = 0x00;
ip6->s6_addr[ 5] = 0x00;
ip6->s6_addr[ 6] = 0x00;
ip6->s6_addr[ 7] = 0x00;
ip6->s6_addr[ 8] = 0x00;
ip6->s6_addr[ 9] = 0x00;
ip6->s6_addr[10] = 0x00;
ip6->s6_addr[11] = 0x00;
ip6->s6_addr[12] = 0x00;
ip6->s6_addr[13] = 0x06;
ip6->s6_addr[14] = 0x00;
ip6->s6_addr[15] = 0x7f;
inet_pton(AF_INET6,"2001:DB8::6:7E",ip6);
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in6);
debug_addr_info[0].ai_next= & debug_addr_info[1];

View File

@ -524,28 +524,6 @@ static int set_directory_permissions(const char *dir, const char *os_user)
}
/*
Give directory permissions for special service user NT SERVICE\servicename
this user is available only on Win7 and later.
*/
void grant_directory_permissions_to_service()
{
char service_user[MAX_PATH+ 12];
OSVERSIONINFO info;
info.dwOSVersionInfoSize= sizeof(info);
GetVersionEx(&info);
if (info.dwMajorVersion >6 ||
(info.dwMajorVersion== 6 && info.dwMinorVersion > 0)
&& opt_service)
{
my_snprintf(service_user,sizeof(service_user), "NT SERVICE\\%s",
opt_service);
set_directory_permissions(opt_datadir, service_user);
}
}
/* Create database instance (including registering as service etc) .*/
static int create_db_instance()
@ -668,7 +646,6 @@ static int create_db_instance()
if (opt_service && opt_service[0])
{
ret= register_service();
grant_directory_permissions_to_service();
if (ret)
goto end;
}

View File

@ -2738,7 +2738,7 @@ static void network_init(void)
#ifdef _WIN32
/* create named pipe */
if (Service.IsNT() && mysqld_unix_port[0] && !opt_bootstrap &&
if (mysqld_unix_port[0] && !opt_bootstrap &&
opt_enable_named_pipe)
{
@ -6162,7 +6162,7 @@ int mysqld_main(int argc, char **argv)
mysql_mutex_unlock(&LOCK_thread_count);
#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY)
if (Service.IsNT() && start_mode)
if (start_mode)
Service.Stop();
else
{
@ -6305,18 +6305,17 @@ int mysqld_main(int argc, char **argv)
return 1;
}
if (Service.GetOS()) /* true NT family */
{
char file_path[FN_REFLEN];
my_path(file_path, argv[0], ""); /* Find name in path */
fn_format(file_path,argv[0],file_path,"",
MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
fn_format(file_path,argv[0],file_path,"", MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
if (argc == 2)
{
if (!default_service_handling(argv, MYSQL_SERVICENAME, MYSQL_SERVICENAME,
file_path, "", NULL))
return 0;
if (Service.IsService(argv[1])) /* Start an optional service */
{
/*
@ -6385,7 +6384,7 @@ int mysqld_main(int argc, char **argv)
Service.Init(MYSQL_SERVICENAME, mysql_service);
return 0;
}
}
/* Start as standalone server */
Service.my_argc=argc;
Service.my_argv=argv;

View File

@ -64,19 +64,6 @@ NTService::~NTService()
-------------------------------------------------------------------------- */
BOOL NTService::GetOS()
{
bOsNT = FALSE;
memset(&osVer, 0, sizeof(OSVERSIONINFO));
osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osVer))
{
if (osVer.dwPlatformId == VER_PLATFORM_WIN32_NT)
bOsNT = TRUE;
}
return bOsNT;
}
/**
Registers the main service thread with the service manager.

View File

@ -45,8 +45,6 @@ class NTService
int nError;
DWORD dwState;
BOOL GetOS(); // returns TRUE if WinNT
BOOL IsNT() { return bOsNT;}
//init service entry point
long Init(LPCSTR szInternName,void *ServiceThread);

View File

@ -979,7 +979,7 @@ static int check_connection(THD *thd)
struct in_addr *ip4= &((struct sockaddr_in *) sa)->sin_addr;
/* See RFC 5737, 192.0.2.0/24 is reserved. */
const char* fake= "192.0.2.4";
ip4->s_addr= inet_addr(fake);
inet_pton(AF_INET,fake, &ip4);
strcpy(ip, fake);
peer_rc= 0;
}

View File

@ -142,6 +142,10 @@ typedef long long longlong;
#ifdef _WIN32
/* inet_aton needs winsock library */
#pragma comment(lib, "ws2_32")
#if _MSC_VER
/* Silence warning about deprecated functions , gethostbyname etc*/
#pragma warning(disable : 4996)
#endif
#endif
#ifdef HAVE_DLOPEN

View File

@ -332,6 +332,7 @@ IF(MSVC)
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
ENDIF()
# Install some extra files that belong to connect engine

View File

@ -108,6 +108,9 @@ Rdb_sst_file_ordered::Rdb_sst_file::put(const rocksdb::Slice &key,
// Add the specified key/value to the sst file writer
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#ifdef _MSC_VER
#pragma warning (disable : 4996)
#endif
return m_sst_file_writer->Add(key, value);
}

View File

@ -9,6 +9,8 @@ IF(MSVC)
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267")
ENDIF()
# Disable warning about deprecated functions, inet_aton
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
ENDIF()
IF(MSVC)