Skip to content

Commit 282b652

Browse files
committed
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.
1 parent d995dd2 commit 282b652

File tree

13 files changed

+94
-178
lines changed

13 files changed

+94
-178
lines changed

cmake/os/Windows.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ IF(MSVC)
146146
ENDIF()
147147

148148
#TODO: update the code and remove the disabled warnings
149-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /we4700 /we4311 /we4477 /we4302 /we4090")
150-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4291 /wd4996 /we4099 /we4700 /we4311 /we4477 /we4302 /we4090")
149+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4700 /we4311 /we4477 /we4302 /we4090")
150+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4291 /we4099 /we4700 /we4311 /we4477 /we4302 /we4090")
151+
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
151152
IF(MYSQL_MAINTAINER_MODE MATCHES "ERR")
152153
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
153154
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")

mysys/my_windac.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@
1717
#include "m_string.h"
1818
#ifdef __WIN__
1919

20-
/* Windows NT/2000 discretionary access control utility functions. */
21-
22-
/*
23-
Check if the operating system is built on NT technology.
24-
25-
RETURN
26-
0 Windows 95/98/Me
27-
1 otherwise
28-
*/
29-
30-
static my_bool is_nt()
31-
{
32-
return GetVersion() < 0x80000000;
33-
}
34-
3520
/*
3621
Auxiliary structure to store pointers to the data which we need to keep
3722
around while SECURITY_ATTRIBUTES is in use.
@@ -86,12 +71,6 @@ int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror,
8671
PSID owner_sid;
8772
My_security_attr *attr;
8873

89-
if (! is_nt())
90-
{
91-
*psa= 0;
92-
return 0;
93-
}
94-
9574
/*
9675
Get SID of Everyone group. Easier to retrieve all SIDs each time
9776
this function is called than worry about thread safety.

plugin/feedback/utils.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static int uname(struct utsname *buf)
9292
{
9393
OSVERSIONINFOEX ver;
9494
ver.dwOSVersionInfoSize = (DWORD)sizeof(ver);
95+
#ifdef _MSC_VER
96+
#pragma warning (disable : 4996)
97+
#endif
9598
if (!GetVersionEx((OSVERSIONINFO *)&ver))
9699
return -1;
97100

sql/hostname.cc

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,11 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
701701
static struct addrinfo debug_addr_info[2];
702702
/* Simulating ipv4 192.0.2.126 */
703703
debug_addr= & debug_sock_addr[0];
704-
debug_addr->sin_family= AF_INET;
705-
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.126");
704+
inet_pton(AF_INET,"192.0.2.126",debug_addr);
706705

707706
/* Simulating ipv4 192.0.2.127 */
708707
debug_addr= & debug_sock_addr[1];
709-
debug_addr->sin_family= AF_INET;
710-
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.127");
708+
inet_pton(AF_INET,"192.0.2.127",debug_addr);
711709

712710
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
713711
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in);
@@ -733,13 +731,11 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
733731
static struct addrinfo debug_addr_info[2];
734732
/* Simulating ipv4 192.0.2.5 */
735733
debug_addr= & debug_sock_addr[0];
736-
debug_addr->sin_family= AF_INET;
737-
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.5");
734+
inet_pton(AF_INET,"192.0.2.5",debug_addr);
738735

739736
/* Simulating ipv4 192.0.2.4 */
740737
debug_addr= & debug_sock_addr[1];
741-
debug_addr->sin_family= AF_INET;
742-
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.4");
738+
inet_pton(AF_INET,"192.0.2.5",debug_addr);
743739

744740
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
745741
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in);
@@ -772,47 +768,13 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
772768
static struct addrinfo debug_addr_info[2];
773769
/* Simulating ipv6 2001:DB8::6:7E */
774770
debug_addr= & debug_sock_addr[0];
775-
debug_addr->sin6_family= AF_INET6;
776771
ip6= & debug_addr->sin6_addr;
777-
/* inet_pton not available on Windows XP. */
778-
ip6->s6_addr[ 0] = 0x20;
779-
ip6->s6_addr[ 1] = 0x01;
780-
ip6->s6_addr[ 2] = 0x0d;
781-
ip6->s6_addr[ 3] = 0xb8;
782-
ip6->s6_addr[ 4] = 0x00;
783-
ip6->s6_addr[ 5] = 0x00;
784-
ip6->s6_addr[ 6] = 0x00;
785-
ip6->s6_addr[ 7] = 0x00;
786-
ip6->s6_addr[ 8] = 0x00;
787-
ip6->s6_addr[ 9] = 0x00;
788-
ip6->s6_addr[10] = 0x00;
789-
ip6->s6_addr[11] = 0x00;
790-
ip6->s6_addr[12] = 0x00;
791-
ip6->s6_addr[13] = 0x06;
792-
ip6->s6_addr[14] = 0x00;
793-
ip6->s6_addr[15] = 0x7e;
772+
inet_pton(AF_INET6,"2001:DB8::6:7E",ip6);
794773

795774
/* Simulating ipv6 2001:DB8::6:7F */
796775
debug_addr= & debug_sock_addr[1];
797-
debug_addr->sin6_family= AF_INET6;
798776
ip6= & debug_addr->sin6_addr;
799-
ip6->s6_addr[ 0] = 0x20;
800-
ip6->s6_addr[ 1] = 0x01;
801-
ip6->s6_addr[ 2] = 0x0d;
802-
ip6->s6_addr[ 3] = 0xb8;
803-
ip6->s6_addr[ 4] = 0x00;
804-
ip6->s6_addr[ 5] = 0x00;
805-
ip6->s6_addr[ 6] = 0x00;
806-
ip6->s6_addr[ 7] = 0x00;
807-
ip6->s6_addr[ 8] = 0x00;
808-
ip6->s6_addr[ 9] = 0x00;
809-
ip6->s6_addr[10] = 0x00;
810-
ip6->s6_addr[11] = 0x00;
811-
ip6->s6_addr[12] = 0x00;
812-
ip6->s6_addr[13] = 0x06;
813-
ip6->s6_addr[14] = 0x00;
814-
ip6->s6_addr[15] = 0x7f;
815-
777+
inet_pton(AF_INET6,"2001:DB8::6:7E",ip6);
816778
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
817779
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in6);
818780
debug_addr_info[0].ai_next= & debug_addr_info[1];

sql/mysql_install_db.cc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,28 +524,6 @@ static int set_directory_permissions(const char *dir, const char *os_user)
524524
}
525525

526526

527-
/*
528-
Give directory permissions for special service user NT SERVICE\servicename
529-
this user is available only on Win7 and later.
530-
*/
531-
532-
void grant_directory_permissions_to_service()
533-
{
534-
char service_user[MAX_PATH+ 12];
535-
OSVERSIONINFO info;
536-
info.dwOSVersionInfoSize= sizeof(info);
537-
GetVersionEx(&info);
538-
if (info.dwMajorVersion >6 ||
539-
(info.dwMajorVersion== 6 && info.dwMinorVersion > 0)
540-
&& opt_service)
541-
{
542-
my_snprintf(service_user,sizeof(service_user), "NT SERVICE\\%s",
543-
opt_service);
544-
set_directory_permissions(opt_datadir, service_user);
545-
}
546-
}
547-
548-
549527
/* Create database instance (including registering as service etc) .*/
550528

551529
static int create_db_instance()
@@ -668,7 +646,6 @@ static int create_db_instance()
668646
if (opt_service && opt_service[0])
669647
{
670648
ret= register_service();
671-
grant_directory_permissions_to_service();
672649
if (ret)
673650
goto end;
674651
}

sql/mysqld.cc

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ static void network_init(void)
27382738

27392739
#ifdef _WIN32
27402740
/* create named pipe */
2741-
if (Service.IsNT() && mysqld_unix_port[0] && !opt_bootstrap &&
2741+
if (mysqld_unix_port[0] && !opt_bootstrap &&
27422742
opt_enable_named_pipe)
27432743
{
27442744

@@ -6162,7 +6162,7 @@ int mysqld_main(int argc, char **argv)
61626162
mysql_mutex_unlock(&LOCK_thread_count);
61636163

61646164
#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY)
6165-
if (Service.IsNT() && start_mode)
6165+
if (start_mode)
61666166
Service.Stop();
61676167
else
61686168
{
@@ -6305,87 +6305,86 @@ int mysqld_main(int argc, char **argv)
63056305
return 1;
63066306
}
63076307

6308-
if (Service.GetOS()) /* true NT family */
6308+
6309+
char file_path[FN_REFLEN];
6310+
my_path(file_path, argv[0], ""); /* Find name in path */
6311+
fn_format(file_path,argv[0],file_path,"", MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
6312+
6313+
if (argc == 2)
63096314
{
6310-
char file_path[FN_REFLEN];
6311-
my_path(file_path, argv[0], ""); /* Find name in path */
6312-
fn_format(file_path,argv[0],file_path,"",
6313-
MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
6315+
if (!default_service_handling(argv, MYSQL_SERVICENAME, MYSQL_SERVICENAME,
6316+
file_path, "", NULL))
6317+
return 0;
63146318

6315-
if (argc == 2)
6316-
{
6317-
if (!default_service_handling(argv, MYSQL_SERVICENAME, MYSQL_SERVICENAME,
6318-
file_path, "", NULL))
6319-
return 0;
6320-
if (Service.IsService(argv[1])) /* Start an optional service */
6321-
{
6322-
/*
6323-
Only add the service name to the groups read from the config file
6324-
if it's not "MySQL". (The default service name should be 'mysqld'
6325-
but we started a bad tradition by calling it MySQL from the start
6326-
and we are now stuck with it.
6327-
*/
6328-
if (my_strcasecmp(system_charset_info, argv[1],"mysql"))
6329-
load_default_groups[load_default_groups_sz-2]= argv[1];
6330-
start_mode= 1;
6331-
Service.Init(argv[1], mysql_service);
6332-
return 0;
6333-
}
6334-
}
6335-
else if (argc == 3) /* install or remove any optional service */
6336-
{
6337-
if (!default_service_handling(argv, argv[2], argv[2], file_path, "",
6338-
NULL))
6339-
return 0;
6340-
if (Service.IsService(argv[2]))
6341-
{
6342-
/*
6343-
mysqld was started as
6344-
mysqld --defaults-file=my_path\my.ini service-name
6345-
*/
6346-
use_opt_args=1;
6347-
opt_argc= 2; // Skip service-name
6348-
opt_argv=argv;
6349-
start_mode= 1;
6350-
if (my_strcasecmp(system_charset_info, argv[2],"mysql"))
6351-
load_default_groups[load_default_groups_sz-2]= argv[2];
6352-
Service.Init(argv[2], mysql_service);
6353-
return 0;
6354-
}
6355-
}
6356-
else if (argc == 4 || argc == 5)
6319+
if (Service.IsService(argv[1])) /* Start an optional service */
63576320
{
63586321
/*
6359-
This may seem strange, because we handle --local-service while
6360-
preserving 4.1's behavior of allowing any one other argument that is
6361-
passed to the service on startup. (The assumption is that this is
6362-
--defaults-file=file, but that was not enforced in 4.1, so we don't
6363-
enforce it here.)
6322+
Only add the service name to the groups read from the config file
6323+
if it's not "MySQL". (The default service name should be 'mysqld'
6324+
but we started a bad tradition by calling it MySQL from the start
6325+
and we are now stuck with it.
63646326
*/
6365-
const char *extra_opt= NullS;
6366-
const char *account_name = NullS;
6367-
int index;
6368-
for (index = 3; index < argc; index++)
6369-
{
6370-
if (!strcmp(argv[index], "--local-service"))
6371-
account_name= "NT AUTHORITY\\LocalService";
6372-
else
6373-
extra_opt= argv[index];
6374-
}
6375-
6376-
if (argc == 4 || account_name)
6377-
if (!default_service_handling(argv, argv[2], argv[2], file_path,
6378-
extra_opt, account_name))
6379-
return 0;
6327+
if (my_strcasecmp(system_charset_info, argv[1],"mysql"))
6328+
load_default_groups[load_default_groups_sz-2]= argv[1];
6329+
start_mode= 1;
6330+
Service.Init(argv[1], mysql_service);
6331+
return 0;
63806332
}
6381-
else if (argc == 1 && Service.IsService(MYSQL_SERVICENAME))
6333+
}
6334+
else if (argc == 3) /* install or remove any optional service */
6335+
{
6336+
if (!default_service_handling(argv, argv[2], argv[2], file_path, "",
6337+
NULL))
6338+
return 0;
6339+
if (Service.IsService(argv[2]))
63826340
{
6383-
/* start the default service */
6341+
/*
6342+
mysqld was started as
6343+
mysqld --defaults-file=my_path\my.ini service-name
6344+
*/
6345+
use_opt_args=1;
6346+
opt_argc= 2; // Skip service-name
6347+
opt_argv=argv;
63846348
start_mode= 1;
6385-
Service.Init(MYSQL_SERVICENAME, mysql_service);
6349+
if (my_strcasecmp(system_charset_info, argv[2],"mysql"))
6350+
load_default_groups[load_default_groups_sz-2]= argv[2];
6351+
Service.Init(argv[2], mysql_service);
63866352
return 0;
63876353
}
63886354
}
6355+
else if (argc == 4 || argc == 5)
6356+
{
6357+
/*
6358+
This may seem strange, because we handle --local-service while
6359+
preserving 4.1's behavior of allowing any one other argument that is
6360+
passed to the service on startup. (The assumption is that this is
6361+
--defaults-file=file, but that was not enforced in 4.1, so we don't
6362+
enforce it here.)
6363+
*/
6364+
const char *extra_opt= NullS;
6365+
const char *account_name = NullS;
6366+
int index;
6367+
for (index = 3; index < argc; index++)
6368+
{
6369+
if (!strcmp(argv[index], "--local-service"))
6370+
account_name= "NT AUTHORITY\\LocalService";
6371+
else
6372+
extra_opt= argv[index];
6373+
}
6374+
6375+
if (argc == 4 || account_name)
6376+
if (!default_service_handling(argv, argv[2], argv[2], file_path,
6377+
extra_opt, account_name))
6378+
return 0;
6379+
}
6380+
else if (argc == 1 && Service.IsService(MYSQL_SERVICENAME))
6381+
{
6382+
/* start the default service */
6383+
start_mode= 1;
6384+
Service.Init(MYSQL_SERVICENAME, mysql_service);
6385+
return 0;
6386+
}
6387+
63896388
/* Start as standalone server */
63906389
Service.my_argc=argc;
63916390
Service.my_argv=argv;

sql/nt_servc.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,6 @@ NTService::~NTService()
6464
6565
-------------------------------------------------------------------------- */
6666

67-
BOOL NTService::GetOS()
68-
{
69-
bOsNT = FALSE;
70-
memset(&osVer, 0, sizeof(OSVERSIONINFO));
71-
osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
72-
if (GetVersionEx(&osVer))
73-
{
74-
if (osVer.dwPlatformId == VER_PLATFORM_WIN32_NT)
75-
bOsNT = TRUE;
76-
}
77-
return bOsNT;
78-
}
79-
8067

8168
/**
8269
Registers the main service thread with the service manager.

sql/nt_servc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class NTService
4545
int nError;
4646
DWORD dwState;
4747

48-
BOOL GetOS(); // returns TRUE if WinNT
49-
BOOL IsNT() { return bOsNT;}
5048
//init service entry point
5149
long Init(LPCSTR szInternName,void *ServiceThread);
5250

sql/sql_connect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int check_connection(THD *thd)
979979
struct in_addr *ip4= &((struct sockaddr_in *) sa)->sin_addr;
980980
/* See RFC 5737, 192.0.2.0/24 is reserved. */
981981
const char* fake= "192.0.2.4";
982-
ip4->s_addr= inet_addr(fake);
982+
inet_pton(AF_INET,fake, &ip4);
983983
strcpy(ip, fake);
984984
peer_rc= 0;
985985
}

sql/udf_example.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ typedef long long longlong;
142142
#ifdef _WIN32
143143
/* inet_aton needs winsock library */
144144
#pragma comment(lib, "ws2_32")
145+
#if _MSC_VER
146+
/* Silence warning about deprecated functions , gethostbyname etc*/
147+
#pragma warning(disable : 4996)
148+
#endif
145149
#endif
146150

147151
#ifdef HAVE_DLOPEN

0 commit comments

Comments
 (0)