Uniform snwprintf() across MinGW and MSVC compilers
PATCH 1/1 Uniform snwprintf() across MinGW and MSVC compilers
MinGW's snwprintf() is a replacement for ISO C's swprintf() used by MSVC. MSVC also provides _snwprintf(), however using it leads to unportable code.
After a discussion with Selva Nair on devel mailing list, an agreement was reached to use swprintf() for MSVC builds.
This patch uniforms snwprintf() usage while making it compile using MinGW and MSVC.
Assigning _snwprintf() return value to unused variable was also removed at one occasion.
--- config-msvc.h | 3 ++- src/openvpn/tun.c | 2 +- src/openvpnserv/interactive.c | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-)
config-msvc.h +2 -1
@@ -93,9 +93,10 @@#define strncasecmp strnicmp#define strcasecmp _stricmp -#if _MSC_VER<1900 +#if _MSC_VER <1900 #define snprintf _snprintf#endif +#define snwprintf swprintf#if _MSC_VER <1800 #define strtoull strtoul
src/openvpn/tun.c +1 -1
@@ -4622,7 +4622,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -_snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); wbuf [SIZE (wbuf) -1 ] =0 ;if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) {
src/openvpnserv/interactive.c +4 -4
@@ -276,7 +276,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events)* Same format as error messages (3 line string) with error = 0 in * 0x%08x format, PID on line 2 and a description "Process ID" on line 3 */ -_snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); +snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); buf[_countof (buf) -1 ] ='\0' ;WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events);
@@ -1066,7 +1066,7 @@ RegisterDNS(LPVOID unused)if (GetSystemDirectory (sys_path,MAX_PATH )) { -_snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); +snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); ipcfg[MAX_PATH -1 ] =L'\0' ; }
@@ -1706,8 +1706,8 @@ RunOpenvpn(LPVOID p)else if (exit_code !=0 ) {WCHAR buf[256 ]; -int len =_snwprintf (buf,_countof (buf), -L"OpenVPN exited with error: exit code = %lu" , exit_code); +snwprintf (buf,_countof (buf), +L"OpenVPN exited with error: exit code = %lu" , exit_code); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_OPENVPN_STARTUP , buf,1 , &exit_event); }
Signature · 1 line
2.9.0.windows.1
This is a follow-up (or better worded: a replacement) patch for "[PATCH 01/13] snwprintf() => _snwprintf()".
I have taken into consideration all Selva's recommendations.
Best regards,
Simon
Quoted 9 lines
-----Original Message-----
From: Simon Rozman [mailto:[email protected]...]
Sent: Thursday, October 12, 2017 9:25 AM
To: [email protected]
Cc: Simon Rozman
Subject: [PATCH] Uniformsnwprintf()across MinGW and MSVC compilersMinGW's
snwprintf()is a replacement for ISO C'sswprintf()used by MSVC. MSVC also provides_snwprintf(), however using it leads to unportable
code.
Quoted 48 lines
After a discussion with Selva Nair on devel mailing list, an agreement was reached to use
swprintf()for MSVC builds.This patch uniforms
snwprintf()usage while making it compile using MinGW and MSVC.Assigning
_snwprintf()return value to unused variable was also removed at one occasion.--- config-msvc.h | 3 ++- src/openvpn/tun.c | 2 +- src/openvpnserv/interactive.c | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-)config-msvc.h +2
-1@@ -93,9 +93,10 @@#define strncasecmp strnicmp#define strcasecmp _stricmp -#if _MSC_VER<1900 +#if _MSC_VER <1900 #define snprintf _snprintf#endif +#define snwprintf swprintf#if _MSC_VER <1800 #define strtoull strtoulsrc/openvpn/tun.c index 3639718..9e3ca41 renamed from src/openvpn/tun.c +0
-0100644
src/openvpn/tun.c +1
-1@@ -4622,7 +4622,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -_snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); wbuf [SIZE (wbuf) -1 ] =0 ;if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) {src/openvpnserv/interactive.c +0
-0
src/openvpnserv/interactive.c ReturnProcessId(HANDLE pipe, DWORD pid, DWORD · line 278
Quoted 3 lines
src/openvpnserv/interactive.c +0
-0@@ -276,7 +276,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) * Same format as error messages (3 line string) with error = 0 in * 0x%08x format, PID on line 2 and a description "Process ID" on
line 3
Quoted 11 lines
src/openvpnserv/interactive.c +1
-1*/ -_snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); +snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); buf[_countof (buf) -1 ] ='\0' ;WritePipeAsync(pipe, buf, wcslen(buf) * 2, count, events); @@ -1066,7+1066,7 @@ RegisterDNS(LPVOID unused)
if (
GetSystemDirectory(sys_path, MAX_PATH))
{
- _snwprintf(ipcfg,MAX_PATH, L"%s\\%s",sys_path,
L"ipconfig.exe");
src/openvpnserv/interactive.c RunOpenvpn(LPVOID p) · line 1710
Quoted 11 lines
src/openvpnserv/interactive.c +2
-2+snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path, +L"ipconfig.exe" ); ipcfg[MAX_PATH -1 ] =L'\0' ; }@@ -1706,8 +1706,8 @@ RunOpenvpn(LPVOID p)else if (exit_code !=0 ) {WCHAR buf[256 ]; - int len = _snwprintf(buf, _countof(buf), - L"OpenVPN exited with error: exit code =
%lu", exit_code);
Quoted 8 lines
src/openvpnserv/interactive.c +3
-1+snwprintf (buf,_countof (buf), +L"OpenVPN exited with error: exit code = %lu" , + exit_code); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_OPENVPN_STARTUP , buf,1 , &exit_event); } --2.9.0.windows.1
Hi Simon,
Quoted 5 lines · Simon Rozman
This is a follow-up (or better worded: a replacement) patch for "[PATCH 01/13]
snwprintf()=>_snwprintf()".I have taken into consideration all Selva's recommendations.
In case you weren't, you can write comments like the one above right after the '---' in the patch itself.
This way you don't need to rush to reply to your own patch, but everything comes together.
So basically you first create the patch with git-format-patch, then edit it and then send it with git-send-email.
Quoted 10 lines
Best regards,
SimonQuoted 7 lines
-----Original Message-----
From: Simon Rozman [mailto:[email protected]...]
Sent: Thursday, October 12, 2017 9:25 AM
To: [email protected]
Cc: Simon Rozman
Subject: [PATCH] Uniformsnwprintf()across MinGW and MSVC compilers
Quoted 13 lines
Quoted 2 lines
MinGW's
snwprintf()is a replacement for ISO C'sswprintf()used by MSVC. MSVC also provides_snwprintf(), however using it leads to unportablecode.
Quoted 10 lines
After a discussion with Selva Nair on devel mailing list, an agreement was reached to use
swprintf()for MSVC builds.This patch uniforms
snwprintf()usage while making it compile using MinGW and MSVC.Assigning
_snwprintf()return value to unused variable was also removed at one occasion.
---
Here you can write what you want. This text will be dropped when applying the patch.
Cheers,
Quoted 88 lines
Quoted 38 lines
config-msvc.h | 3 ++- src/openvpn/tun.c | 2 +- src/openvpnserv/interactive.c | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-)config-msvc.h +2
-1@@ -93,9 +93,10 @@#define strncasecmp strnicmp#define strcasecmp _stricmp -#if _MSC_VER<1900 +#if _MSC_VER <1900 #define snprintf _snprintf#endif +#define snwprintf swprintf#if _MSC_VER <1800 #define strtoull strtoulsrc/openvpn/tun.c index 3639718..9e3ca41 renamed from src/openvpn/tun.c +0
-0100644
src/openvpn/tun.c +1
-1@@ -4622,7 +4622,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -_snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); wbuf [SIZE (wbuf) -1 ] =0 ;if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) {src/openvpnserv/interactive.c +0
-0src/openvpnserv/interactive.c ReturnProcessId(HANDLE pipe, DWORD pid, DWORD · line 278
Quoted 3 lines
src/openvpnserv/interactive.c +0
-0@@ -276,7 +276,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) * Same format as error messages (3 line string) with error = 0 in * 0x%08x format, PID on line 2 and a description "Process ID" online 3
Quoted 11 lines
src/openvpnserv/interactive.c +1
-1*/ -_snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); +snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); buf[_countof (buf) -1 ] ='\0' ;WritePipeAsync(pipe, buf, wcslen(buf) * 2, count, events); @@ -1066,7+1066,7 @@ RegisterDNS(LPVOID unused)
if (
GetSystemDirectory(sys_path, MAX_PATH))
{
- _snwprintf(ipcfg,MAX_PATH, L"%s\\%s",sys_path,L"ipconfig.exe");
src/openvpnserv/interactive.c RunOpenvpn(LPVOID p) · line 1710
Quoted 11 lines
src/openvpnserv/interactive.c +2
-2+snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path, +L"ipconfig.exe" ); ipcfg[MAX_PATH -1 ] =L'\0' ; }@@ -1706,8 +1706,8 @@ RunOpenvpn(LPVOID p)else if (exit_code !=0 ) {WCHAR buf[256 ]; - int len = _snwprintf(buf, _countof(buf), - L"OpenVPN exited with error: exit code =%lu",
exit_code);Quoted 8 lines
src/openvpnserv/interactive.c +3
-1+snwprintf (buf,_countof (buf), +L"OpenVPN exited with error: exit code = %lu" , + exit_code); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_OPENVPN_STARTUP , buf,1 , &exit_event); } --2.9.0.windows.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
Antonio Quartulli
Hi,
For book keeping its easier if version 2 of a patch is sent to the same thread as
the original (e.g., use --in-reply-to: <msgid> in git send-email) and [PATCH v2 01/13]
in header.
Anyway, this one is v2 of [PATCH 01/13]
https://www.mail-archive.com/[email protected]...
.net/msg15583.html
Quoted 2 lines · Simon Rozman
MinGW's
snwprintf()is a replacement for ISO C'sswprintf()used by MSVC.
A confusing statement as MinGW too has 'swprintf' and my suggestion was to just use 'swprintf' both for mingw and MSVC. Then neither build would depend on non-standard variants.
That said its fine if you want to keep this as just an MSVC compliance patch..
Quoted 82 lines
MSVC also provides
_snwprintf(), however using it leads to unportable code.After a discussion with Selva Nair on devel mailing list, an agreement was reached to use
swprintf()for MSVC builds.This patch uniforms
snwprintf()usage while making it compile using MinGW and MSVC.Assigning
_snwprintf()return value to unused variable was also removed at one occasion.--- config-msvc.h | 3 ++- src/openvpn/tun.c | 2 +- src/openvpnserv/interactive.c | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-)config-msvc.h +2
-1@@ -93,9 +93,10 @@#define strncasecmp strnicmp#define strcasecmp _stricmp -#if _MSC_VER<1900 +#if _MSC_VER <1900 #define snprintf _snprintf#endif +#define snwprintf swprintf#if _MSC_VER <1800 #define strtoull strtoul
src/openvpn/tun.c +1
-1@@ -4622,7 +4622,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -_snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); wbuf [SIZE (wbuf) -1 ] =0 ;if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) {src/openvpnserv/interactive.c +0
-0@@ -276,7 +276,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) * Same format as error messages (3 line string) with error = 0 in * 0x%08x format, PID on line 2 and a description "Process ID" online 3
*/src/openvpnserv/interactive.c +4
-4-_snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); +snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); buf[_countof (buf) -1 ] ='\0' ;WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events);@@ -1066,7 +1066,7 @@ RegisterDNS(LPVOID unused)if (GetSystemDirectory (sys_path,MAX_PATH )) { -_snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); +snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); ipcfg[MAX_PATH -1 ] =L'\0' ; }@@ -1706,8 +1706,8 @@ RunOpenvpn(LPVOID p)else if (exit_code !=0 ) {WCHAR buf[256 ]; -int len =_snwprintf (buf,_countof (buf), - L"OpenVPN exited with error: exit code = %lu", exit_code); + snwprintf(buf,_countof (buf), +L"OpenVPN exited with error: exit code = %lu" , exit_code); buf[_countof (buf) -1 ] =L'\0' ;
Quoted 3 lines
ReturnError(pipe, ERROR_OPENVPN_STARTUP, buf, 1, &exit_event);
}As said above, I would have replaced all _snwprintf and snwprintf by swprintf and avoided the #define. That has the added advantage that mingw builds also will no longer depend on the non-standard snwprintf.
Nevertheless I'm ok with this unless someone else objects.
Selva
Hi,
Quoted 5 lines
For book keeping its easier if version 2 of a patch is sent to the same thread
as the original (e.g., use --in-reply-to: <msgid> in git send-email) and [PATCH
v2 01/13] in header.
Thank you, I'll learn the team-play. Please have patience with me. :)
Quoted 6 lines
Quoted 2 lines · Simon Rozman
MinGW's
snwprintf()is a replacement for ISO C'sswprintf()used by MSVC.A confusing statement as MinGW too has 'swprintf' and my suggestion was to just use 'swprintf' both for mingw and MSVC. Then neither build would depend on non-standard variants.
Actually, the statement would have been correct if you change "MSVC" to "MSVC2017".
Quoted 4 lines
As said above, I would have replaced all
_snwprintfand snwprintf by swprintf
and avoided the #define. That has the added advantage that mingw builds also will no longer depend on the non-standard snwprintf.
Are you sure MinGW supports swprintf() in an ISO C conformant way? People all over the web complain about MinGW's non-ISO C conformant swprintf() declaration being a legacy of VC 6.0 runtime library used:
https://stackoverflow.com/questions/35072373/swprintf-declaration-mismatch
As said before, I am not familiar with MinGW. I read OpenVPN has a patched version of it. Perhaps you moved to a more recent VC runtime library meanwhile.
If we change _snwprintf/snwprintf() to swprintf() as you suggested, I am afraid OpenVPN would not compile on MinGW anymore without #define tweaks. But, this time MinGW will need them, not MSVC*2017*.
Selva, if you can confirm that swprintf() really works on OpenVPN's distribution of MinGW in an ISO C conformant way, I'll gladly use it. I can prepare a patch for you if you can give it a try.
Best regards,
Simon
PATCH 1/1 Uniform swprintf() across MinGW and MSVC compilers
Legacy _snwprintf() and snwprintf() functions replaced with ISO C swprintf().
Assigning _snwprintf() return value to unused variable was also removed at one occasion.
--- src/openvpn/tun.c | 2 +- src/openvpnserv/interactive.c | 20 ++++++++++---------- src/openvpnserv/validate.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-)
src/openvpn/tun.c +1 -1
@@ -4622,7 +4622,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -_snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +swprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); wbuf [SIZE (wbuf) -1 ] =0 ;if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) {
src/openvpnserv/interactive.c +10 -10
@@ -277,7 +277,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events)* Same format as error messages (3 line string) with error = 0 in * 0x%08x format, PID on line 2 and a description "Process ID" on line 3 */ -_snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); +swprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); buf[_countof (buf) -1 ] ='\0' ;WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events);
@@ -403,8 +403,8 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options)if (!CheckOption (workdir,2 , argv_tmp, &settings)) { -snwprintf (buf,_countof (buf), msg1, argv[0 ], workdir, - settings.ovpn_admin_group); +swprintf (buf,_countof (buf), msg1, argv[0 ], workdir, + settings.ovpn_admin_group); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_STARTUP_DATA , buf,1 , &exit_event); }
@@ -422,15 +422,15 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options) {if (wcscmp (L"--config" , argv[i]) ==0 && argc-i >1 ) { -snwprintf (buf,_countof (buf), msg1, argv[i+1 ], workdir, - settings.ovpn_admin_group); +swprintf (buf,_countof (buf), msg1, argv[i+1 ], workdir, + settings.ovpn_admin_group); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_STARTUP_DATA , buf,1 , &exit_event); }else { -snwprintf (buf,_countof (buf), msg2, argv[i], - settings.ovpn_admin_group); +swprintf (buf,_countof (buf), msg2, argv[i], + settings.ovpn_admin_group); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_STARTUP_DATA , buf,1 , &exit_event); }
@@ -1067,7 +1067,7 @@ RegisterDNS(LPVOID unused)if (GetSystemDirectory (sys_path,MAX_PATH )) { -_snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); +swprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); ipcfg[MAX_PATH -1 ] =L'\0' ; }
@@ -1707,8 +1707,8 @@ RunOpenvpn(LPVOID p)else if (exit_code !=0 ) {WCHAR buf[256 ]; -int len =_snwprintf (buf,_countof (buf), -L"OpenVPN exited with error: exit code = %lu" , exit_code); +swprintf (buf,_countof (buf), +L"OpenVPN exited with error: exit code = %lu" , exit_code); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_OPENVPN_STARTUP , buf,1 , &exit_event); }
src/openvpnserv/validate.c +1 -1
@@ -65,7 +65,7 @@ CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -snwprintf (tmp,_countof (tmp),L"%s\\%s" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%s\\%s" , workdir, fname); tmp[_countof (tmp)-1 ] =L'\0' ; config_file = tmp; }
Signature · 6 lines
2.9.0.windows.1 Here's a revised patch that converts all _snwprintf() and snwprintf() oddities to swprintf(). It replaces the previous patch. Hopefuly, this one nails it. Best regards, Simon
Hi,
On Fri, Oct 13, 2017 at 12:55 AM, Simon Rozman <[email protected]...> wrote:
...
Quoted 16 lines
Quoted 5 lines
As said above, I would have replaced all
_snwprintfand snwprintf by swprintf
and avoided the #define. That has the added advantage that mingw builds also will no longer depend on the non-standard snwprintf.Are you sure MinGW supports
swprintf()in an ISO C conformant way? People all
over the web complain about MinGW's non-ISO C conformantswprintf()declaration being a legacy of VC 6.0 runtime library used:
https://stackoverflow.com/questions/35072373/swprintf-declaration-mismatch
As said before, I am not familiar with MinGW. I read OpenVPN has a patched version of it. Perhaps you moved to a more recent VC runtime library meanwhile.
Quoted 4 lines
If we change _snwprintf/snwprintf() to
swprintf()as you suggested, I am afraid OpenVPN would not compile on MinGW anymore without #define tweaks. But,
this time MinGW will need them, not MSVC*2017*.
There are two issues here: sprintf signature in Windows runtime and mingw-w64's support for the standard conforming variant.
@samuli: Which versions of mingw-w64 should we test against to ensure release and snapshot builds would succeed?
Windows runtime used to have an swprintf that does not take the buffer size. But to get that non-conformant behaviour you will need some preprocessor define like ....NON_CONFORMING_SWPRINTF... so hopefully modern VS installations does pick the right function.
As for mingw, note that I use mingw-w64, not the older one from mingw.org. In the former, my understanding is that an implementation based on _vsnwprintf is used unless the above NON_CONFORMING.. define is active.
Probably there are some old mingw releases where this was broken --- I'll test your latest patch. That said, I would not depend on any of these for nul-termination, we should continue to append an explicit L'\0'.
Selva
Quoted 30 lines · Selva
Hi,
On Fri, Oct 13, 2017 at 12:55 AM, Simon Rozman <[email protected]... <mailto:[email protected]...>> wrote:
...Quoted 4 lines
As said above, I would have replaced all
_snwprintfand snwprintf by swprintf
and avoided the #define. That has the added advantage that mingw builds also will no longer depend on the non-standard snwprintf.Are you sure MinGW supports
swprintf()in an ISO C conformant way? People all
over the web complain about MinGW's non-ISO C conformantswprintf()declaration being a legacy of VC 6.0 runtime library used:
https://stackoverflow.com/questions/35072373/swprintf-declaration-mismatch
<https://stackoverflow.com/questions/35072373/swprintf-declaration-mismatch>
As said before, I am not familiar with MinGW. I read OpenVPN has a patched
version of it. Perhaps you moved to a more recent VC runtime library meanwhile.If we change _snwprintf/snwprintf() to
swprintf()as you suggested, I am afraid OpenVPN would not compile on MinGW anymore without #define tweaks. But,
this time MinGW will need them, not MSVC*2017*.
Quoted 5 lines
There are two issues here: sprintf signature in Windows runtime and mingw-w64's support for the standard conforming variant.
@samuli: Which versions of mingw-w64 should we test against to ensure release and snapshot builds would succeed?
Right now _we_ use Ubuntu 16.04 for building:
mingw-w64 4.0.4
gcc-mingw-w64 5.3.1
g++-mingw-w64 5.3.1
That said, I'm pretty sure many people still build with Ubuntu 14.04. So keeping support for it would make sense if it is not horribly painful. This is what Ubuntu 14.04 comes with:
mingw-w64 3.1.0
gcc-mingw-w64 4.8.2
g++-mingw-w64 4.8.2
Samuli
Quoted 16 lines
Windows runtime used to have an swprintf that does not take the buffer size. But to get that non-conformant behaviour you will need some preprocessor define like ....NON_CONFORMING_SWPRINTF... so hopefully modern VS installations does pick the right function.
As for mingw, note that I use mingw-w64, not the older one from mingw.org <http://mingw.org>.
In the former, my understanding is that an implementation based on_vsnwprintfis used unless the aboveNON_CONFORMING.. define is active.Probably there are some old mingw releases where this was broken --- I'll test your latest patch. That said, I would not depend on any of these for nul-termination, we should continue to append an explicit L'\0'.
Selva
2017-10-16 13:05 GMT+05:00 Samuli Seppänen <[email protected]...>:
Quoted 48 lines · Selva
Quoted 8 lines
Hi,
On Fri, Oct 13, 2017 at 12:55 AM, Simon Rozman <[email protected]... <mailto:[email protected]...>> wrote:
...Quoted 1 line
As said above, I would have replaced all
_snwprintfand snwprintfby
Quoted 2 lines
Quoted 2 lines
swprintf
and avoided the #define. That has the added advantage that mingwbuilds
Quoted 7 lines
Quoted 1 line
also will no longer depend on the non-standard snwprintf.
Are you sure MinGW supports
swprintf()in an ISO C conformant way? People all
over the web complain about MinGW's non-ISO C conformantswprintf()declaration being a legacy of VC 6.0 runtime library used:
https://stackoverflow.com/questions/35072373/swprintf-declaration-mismatch
Quoted 1 line
<https://stackoverflow.com/questions/35072373/swprintf-declaration-mismatch>
Quoted 7 lines
As said before, I am not familiar with MinGW. I read OpenVPN has a patched
version of it. Perhaps you moved to a more recent VC runtime library meanwhile.If we change _snwprintf/snwprintf() to
swprintf()as you suggested,I am
Quoted 10 lines
afraid OpenVPN would not compile on MinGW anymore without #define tweaks. But,
this time MinGW will need them, not MSVC*2017*.There are two issues here: sprintf signature in Windows runtime and mingw-w64's support for the standard conforming variant.
@samuli: Which versions of mingw-w64 should we test against to ensure release and snapshot builds would succeed?
Right now _we_ use Ubuntu 16.04 for building:
mingw-w64 4.0.4
gcc-mingw-w64 5.3.1
g++-mingw-w64 5.3.1
Quoted 8 lines
That said, I'm pretty sure many people still build with Ubuntu 14.04. So keeping support for it would make sense if it is not horribly painful. This is what Ubuntu 14.04 comes with:
mingw-w64 3.1.0
gcc-mingw-w64 4.8.2
g++-mingw-w64 4.8.2
I'm afraid, it's not possible to build openvpn with mingw-gcc-4.8.X due to lack of firewall manipulation api
(that's why we use xenial repo during travis-ci build)
Samuli, can you please try to build on ubuntu 14.04 ? am I wrong ?
Quoted 30 lines
Samuli
Quoted 6 lines
Windows runtime used to have an swprintf that does not take the buffer size. But to get that non-conformant behaviour you will need some preprocessor define like ....NON_CONFORMING_SWPRINTF... so hopefully modern VS installations does pick the right function.
Quoted 7 lines
As for mingw, note that I use mingw-w64, not the older one from mingw.org <http://mingw.org>.
In the former, my understanding is that an implementation based on_vsnwprintfis used unless the aboveNON_CONFORMING.. define is active.Probably there are some old mingw releases where this was broken --- I'll test your latest patch. That said, I would not depend on any of
these
Quoted 3 lines
for nul-termination, we should continue to append an explicit L'\0'.
Selva
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi,
Quoted 11 lines · Samuli Seppänen
Quoted 2 lines · Selva
@samuli: Which versions of mingw-w64 should we test against to ensure release and snapshot builds would succeed?
Right now _we_ use Ubuntu 16.04 for building:
mingw-w64 4.0.4
gcc-mingw-w64 5.3.1
g++-mingw-w64 5.3.1
Quoted 8 lines
That said, I'm pretty sure many people still build with Ubuntu 14.04. So keeping support for it would make sense if it is not horribly painful. This is what Ubuntu 14.04 comes with:
mingw-w64 3.1.0
gcc-mingw-w64 4.8.2
g++-mingw-w64 4.8.2
Thanks.
For the purpose of the present discussion (i.e., behaviour of fwprintf), 14.04 is ok.
Selva
Hi
Quoted 19 lines · Илья Шипицин
2017-10-16 13:05 GMT+05:00 Samuli Seppänen <[email protected]...>:
Quoted 15 lines · Selva
Quoted 3 lines
@samuli: Which versions of mingw-w64 should we test against to ensure release and snapshot builds would succeed?
Right now _we_ use Ubuntu 16.04 for building:
mingw-w64 4.0.4
gcc-mingw-w64 5.3.1
g++-mingw-w64 5.3.1That said, I'm pretty sure many people still build with Ubuntu 14.04. So keeping support for it would make sense if it is not horribly painful. This is what Ubuntu 14.04 comes with:
Quoted 9 lines
Quoted 4 lines
mingw-w64 3.1.0
gcc-mingw-w64 4.8.2
g++-mingw-w64 4.8.2I'm afraid, it's not possible to build openvpn with mingw-gcc-4.8.X due to lack of firewall manipulation api
(that's why we use xenial repo during travis-ci build)
Good to know mingw-w64 from xenial is used in the travis-ci script.
I did a quick test on ubuntu trusty (14.04.05 LTS), and as you pointed out, it fails while
compiling block_dns.c because of some errors in the headers for the windows filtering platform API. All the bits are there so its possible to build
after tweaking the installed headers (only a couple of lines) but not something
one would normally want to do.
It does look like targeting 14.04 is no more relevant.
Selva
Hi,
Quoted 10 lines · Selva
I did a quick test on ubuntu trusty (14.04.05 LTS), and as you pointed out, it fails while
compilingblock_dns.cbecause of some errors in the headers for the windows filtering platform API. All the bits are there so its possible to build
after tweaking the installed headers (only a couple of lines) but not something
one would normally want to do.It does look like targeting 14.04 is no more relevant.
I have some sort of mixed feedback from Samuli's buildbots here - it *used* to compile just fine, but since the latest patch (removing the "manual" dynamic linking stuff), it fails with
openvpnserv-interactive.o:interactive.c:(.text+0xee2): undefined reference to `InitializeUnicastIpAddressEntry'
... so it seems 14.04 mingw does not truly expose all the Vista API bits.
OTOH, we can just document "16.04 is what you need" - that would work for me, as cross-building is really not "I have this <any breed of unix
OS> and want to build and run OpenVPN here!" building... (I have much
stricter requirements wrt breaking platforms for "run here" builds :) )
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...2017-10-16 20:33 GMT+05:00 Selva <[email protected]...>:
Quoted 46 lines
Hi
Quoted 19 lines · Илья Шипицин
2017-10-16 13:05 GMT+05:00 Samuli Seppänen <[email protected]...>:
Quoted 15 lines · Selva
Quoted 3 lines
@samuli: Which versions of mingw-w64 should we test against to ensure release and snapshot builds would succeed?
Right now _we_ use Ubuntu 16.04 for building:
mingw-w64 4.0.4
gcc-mingw-w64 5.3.1
g++-mingw-w64 5.3.1That said, I'm pretty sure many people still build with Ubuntu 14.04. So keeping support for it would make sense if it is not horribly painful. This is what Ubuntu 14.04 comes with:
Quoted 9 lines
Quoted 4 lines
mingw-w64 3.1.0
gcc-mingw-w64 4.8.2
g++-mingw-w64 4.8.2I'm afraid, it's not possible to build openvpn with mingw-gcc-4.8.X due to lack of firewall manipulation api
(that's why we use xenial repo during travis-ci build)Good to know mingw-w64 from xenial is used in the travis-ci script.
I did a quick test on ubuntu trusty (14.04.05 LTS), and as you pointed out, it fails while
compilingblock_dns.cbecause of some errors in the headers for the windows filtering platform API. All the bits are there so its possible to build
after tweaking the installed headers (only a couple of lines) but not something
one would normally want to do.
Quoted 2 lines
It does look like targeting 14.04 is no more relevant.
it used to work on 14.04 ... with patched debs (header issue is relatively easy to fix)
however, it does not work now because of not supporting Vista things
yes, 16.04 is just fine
Quoted 3 lines
Selva
Hi,
Quoted 14 lines · Gert Doering
Hi,
Quoted 10 lines · Selva
I did a quick test on ubuntu trusty (14.04.05 LTS), and as you pointed out, it fails while
compilingblock_dns.cbecause of some errors in the headers for the windows filtering platform API. All the bits are there so its possible to build
after tweaking the installed headers (only a couple of lines) but not something
one would normally want to do.It does look like targeting 14.04 is no more relevant.
Quoted 9 lines
I have some sort of mixed feedback from Samuli's buildbots here - it *used* to compile just fine, but since the latest patch (removing the "manual" dynamic linking stuff), it fails with
openvpnserv-interactive.o:interactive.c:(.text+0xee2): undefined reference to `InitializeUnicastIpAddressEntry'
... so it seems 14.04 mingw does not truly expose all the Vista API bits.
My bad, I missed that warning when tested on a 14.04 instance (it was a google compute engine
with 14.04.5 LTS image with mingw-w64 3.1.0). I do now see that ' InitializeUnicastIpAddressEntry'
is missing in there.
As these buildbots used to succeed the other header issues I saw (an extra ifdef
and a duplicate declaration) must be already patched in them.
The function stub is there in the import library library (libiphlpapi.lib), so we could add
VOID NETIOAPI_API_ InitializeUnicastIpAddressEntry (PMIB_UNICASTIPADDRESS_ROW Row);
to interactive.c.
But.
Quoted 5 lines
OTOH, we can just document "16.04 is what you need" - that would work for me, as cross-building is really not "I have this <any breed of unix
OS> and want to build and run OpenVPN here!" building... (I have much
stricter requirements wrt breaking platforms for "run here" builds :) )
I would prefer that option and and we just require 16.04 or better from now on.
Selva
2017-10-16 23:17 GMT+05:00 Selva <[email protected]...>:
Quoted 49 lines
Hi,
Quoted 15 lines · Gert Doering
Hi,
Quoted 4 lines · Selva
I did a quick test on ubuntu trusty (14.04.05 LTS), and as you pointed out, it fails while
compilingblock_dns.cbecause of some errors in the headers for the windows filtering platform API. All the bits are there so its possibleto
Quoted 6 lines
build
after tweaking the installed headers (only a couple of lines) but not something
one would normally want to do.It does look like targeting 14.04 is no more relevant.
Quoted 9 lines
I have some sort of mixed feedback from Samuli's buildbots here - it *used* to compile just fine, but since the latest patch (removing the "manual" dynamic linking stuff), it fails with
openvpnserv-interactive.o:interactive.c:(.text+0xee2): undefined reference to `InitializeUnicastIpAddressEntry'
... so it seems 14.04 mingw does not truly expose all the Vista API bits.
My bad, I missed that warning when tested on a 14.04 instance (it was a google compute engine
with 14.04.5 LTS image with mingw-w64 3.1.0). I do now see that 'InitializeUnicastIpAddressEntry'
is missing in there.As these buildbots used to succeed the other header issues I saw (an extra ifdef
and a duplicate declaration) must be already patched in them.The function stub is there in the import library library (libiphlpapi.lib), so we could add
VOIDNETIOAPI_API_InitializeUnicastIpAddressEntry (PMIB_UNICASTIPADDRESS_ROWRow);
tointeractive.c.But.
Quoted 9 lines
Quoted 5 lines
OTOH, we can just document "16.04 is what you need" - that would work for me, as cross-building is really not "I have this <any breed of unix
OS> and want to build and run OpenVPN here!" building... (I have much
stricter requirements wrt breaking platforms for "run here" builds :) )I would prefer that option and and we just require 16.04 or better from now on.
based on the above, I would say that adding configure check for "InitializeUnicastIpAddressEntry" would be nice (and making configure gently complain like "please use Ubuntu 16.04")
Quoted 4 lines
Selva
Quoted 57 lines · Илья Шипицин
2017-10-16 20:33 GMT+05:00 Selva <[email protected]... <mailto:[email protected]...>>:
Hi
On Mon, Oct 16, 2017 at 4:22 AM, Илья Шипицин <[email protected]... <mailto:[email protected]...>> wrote:
2017-10-16 13:05 GMT+05:00 Samuli Seppänen <[email protected]... <mailto:[email protected]...>>:
On 13/10/2017 20:48, Selva wrote:
> @samuli: Which versions of mingw-w64 should we test against to ensure > release and snapshot builds would succeed?
Right now _we_ use Ubuntu 16.04 for building:
mingw-w64 4.0.4
gcc-mingw-w64 5.3.1
g++-mingw-w64 5.3.1That said, I'm pretty sure many people still build with Ubuntu 14.04. So
keeping support for it would make sense if it is not horribly painful.
This is what Ubuntu 14.04 comes with:mingw-w64 3.1.0
gcc-mingw-w64 4.8.2
g++-mingw-w64 4.8.2I'm afraid, it's not possible to build openvpn with mingw-gcc-4.8.X due to lack of firewall manipulation api (that's why we use xenial repo during travis-ci build)
Good to know mingw-w64 from xenial is used in the travis-ci script.
I did a quick test on ubuntu trusty (14.04.05 LTS), and as you pointed out, it fails while
compilingblock_dns.cbecause of some errors in the headers for the windows filtering platform API. All the bits are there so its possible to build
after tweaking the installed headers (only a couple of lines) but not something
one would normally want to do.It does look like targeting 14.04 is no more relevant.
Quoted 8 lines
it used to work on 14.04 ... with patched debs (header issue is relatively easy to fix)
however, it does not work now because of not supporting Vista things
yes, 16.04 is just fine
I'm fine with dropping support for the Ubuntu 14.04 version of mingw-w64, as the unpatched version does not work anyways. Better keep code at the OpenVPN end as simple as possible.
Signature · 5 lines
Samuli Seppänen Community Manager OpenVPN Technologies, Inc irc freenode net: mattock
Re: [Openvpn-devel] [PATCH] Uniform swprintf() across MinGW and MSVC compilers
In reply to Simon RozmanHi
Quoted 109 lines · Simon Rozman
Legacy
_snwprintf()andsnwprintf()functions replaced with ISO Cswprintf().Assigning
_snwprintf()return value to unused variable was also removed at one occasion.--- src/openvpn/tun.c | 2 +- src/openvpnserv/interactive.c | 20 ++++++++++---------- src/openvpnserv/validate.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-)src/openvpn/tun.c +1
-1@@ -4622,7 +4622,7 @@ get_adapter_index_method_1(const char *guid)DWORD index;ULONG aindex;wchar_t wbuf[256 ]; -_snwprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); +swprintf (wbuf,SIZE (wbuf),L"\\DEVICE\\TCPIP_%S" , guid); wbuf [SIZE (wbuf) -1 ] =0 ;if (GetAdapterIndex (wbuf, &aindex) !=NO_ERROR ) {src/openvpnserv/interactive.c +0
-0@@ -277,7 +277,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) * Same format as error messages (3 line string) with error = 0 in * 0x%08x format, PID on line 2 and a description "Process ID" online 3
*/src/openvpnserv/interactive.c +3
-3-_snwprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); +swprintf (buf,_countof (buf),L"0x%08x\n0x%08x\n%s" ,0 , pid, msg); buf[_countof (buf) -1 ] ='\0' ;WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events);@@ -403,8 +403,8 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options)if (!CheckOption (workdir,2 , argv_tmp, &settings)) { -snwprintf (buf,_countof (buf), msg1, argv[0 ], workdir, - settings.ovpn_admin_group); +swprintf (buf,_countof (buf), msg1, argv[0 ], workdir, + settings.ovpn_admin_group); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_STARTUP_DATA , buf,1 , &exit_event);}src/openvpnserv/interactive.c +4
-4@@ -422,15 +422,15 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options) {if (wcscmp (L"--config" , argv[i]) ==0 && argc-i >1 ) { -snwprintf (buf,_countof (buf), msg1, argv[i+1 ], workdir, - settings.ovpn_admin_group); +swprintf (buf,_countof (buf), msg1, argv[i+1 ], workdir, + settings.ovpn_admin_group); buf[_countof (buf) -1 ] =L'\0' ;ReturnError (pipe,ERROR_STARTUP_DATA , buf,1 , &exit_event); }else { -snwprintf (buf,_countof (buf), msg2, argv[i], - settings.ovpn_admin_group); +swprintf (buf,_countof (buf), msg2, argv[i], + settings.ovpn_admin_group); buf[_countof (buf) -1 ] =L'\0' ;ReturnError(pipe,
ERROR_STARTUP_DATA, buf, 1,&exit_event); }src/openvpnserv/interactive.c +3
-3@@ -1067,7 +1067,7 @@ RegisterDNS(LPVOID unused)if (GetSystemDirectory (sys_path,MAX_PATH )) { -_snwprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); +swprintf (ipcfg,MAX_PATH ,L"%s\\%s" , sys_path,L"ipconfig.exe" ); ipcfg[MAX_PATH -1 ] =L'\0' ; }@@ -1707,8 +1707,8 @@ RunOpenvpn(LPVOID p)else if (exit_code !=0 ) {WCHAR buf[256 ]; -int len =_snwprintf (buf,_countof (buf), - L"OpenVPN exited with error: exit code = %lu", exit_code); + swprintf(buf,_countof (buf), +L"OpenVPN exited with error: exit code = %lu" , exit_code); buf[_countof (buf) -1 ] =L'\0' ;ReturnError(pipe, ERROR_OPENVPN_STARTUP, buf, 1, &exit_event); }src/openvpnserv/validate.c +1
-1@@ -65,7 +65,7 @@ CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)/* convert fname to full path */ if (PathIsRelativeW (fname) ) { -snwprintf (tmp,_countof (tmp),L"%s\\%s" , workdir, fname); +swprintf (tmp,_countof (tmp),L"%s\\%s" , workdir, fname); tmp[_countof (tmp)-1 ] =L'\0' ; config_file = tmp;
Quoted 2 lines
}
Apart from making MSVC compliant, this unifies varied usages of snwprintf's in the code, converts all into the standard swprintf, and still works with mingw-w64.
Compile tested using mingw-w64 4.0.4 in ubuntu 16.04 and using 3.1.0 in ubuntu 14.04[*]
ACK
Selva
[*] Ubuntu 14.04 needs some tweaks to correctly compile and link for reasons unrelated to this patch.
[Openvpn-devel] [PATCH applied] Re: Uniform swprintf() across MinGW and MSVC compilers
In reply to Simon RozmanYour patch has been applied to the master and release/2.4 branch.
commit 2f7b59196f55d62386cbcb2a889381e91e6c5148 (master) commit 7e36553aa6f0c5ca1944025e0bd09aacb38a41cb (release/2.4)
Author: Simon Rozman Date: Fri Oct 13 11:50:08 2017 +0200
Uniform swprintf() across MinGW and MSVC compilers
Acked-by: Selva Nair <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg15633.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering