Hi,


I agree migration towards ISO-C's snwprintf() is better.



We can do it two way: using #define, or implementing a simple wrapper 
function. The advantage of wrapper function is we can introduce guaranteed 
null-terminated output to match ISO-C experience.



Best regards,

Simon



From: Selva [mailto:selva.n...@gmail.com]
Sent: Wednesday, October 11, 2017 3:20 PM
To: Simon Rozman
Cc: openvpn-devel@lists.sourceforge.net
Subject: Re: [Openvpn-devel] [PATCH 01/13] snwprintf() => _snwprintf()





On Wed, Oct 11, 2017 at 6:06 AM, Simon Rozman <si...@rozman.si> wrote:

Hi,

> From a technical point of view, it looks like a fine patch.  But it is hard
> for me
> (as a non-Windows dev) to understand *why* this is needed.
> It would be good to explain the rationale for a change so others can
> understand it as quickly as possible.

snwprintf() is not defined in Windows SDK. _snwprintf() is.
[https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l]

Mingw probably accepts both. That's why nobody noticed. Looking around OpenVPN
code, I have found some code using _snwprintf(), some snwprintf(). Probably,
since MSVC was neglected for so long, nobody paid attention to such a subtle
difference.

For the code to compile on MSVC all snwprintf() should be replaced with
_snwprintf(). Or, since the prefix underscore imposed by Windows SDK is not
mostly aesthetical, the following #define could be introduced:
#ifdef _MSVC_VER
#define snwprintf _snwprintf
#endif

Nevertheless, I suggest consistent use of snwprintf/_snwprintf.





While its true that mingw accepts both and Windows has only the latter, I 
think the best option here is swprintf. Its ISO-C, does the same thing as 
_snwprintf with added advantage that nul-termination is guaranteed by the 
standard (though we need not bank on that and better continue the practice of 
explicit nul termination).  Note that swprintf is like snprintf in that it 
takes the buffer size as an argument.



Selva





Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
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
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to