2626 *
2727 * SPDX-License-Identifier: BSD-2-Clause
2828 */
29- #ifdef OLD_MSVC
30-
31- #define snprintf _snprintf
32- #define vsnprintf _vsnprintf
33-
34- #else
3529
3630#ifdef ANY_BSD
3731#define _vsnprintf vsnprintf
@@ -41,7 +35,11 @@ static int wtf_snprintf(char *buffer, size_t count, const char *format, ...) {
4135 int result ;
4236 va_list args ;
4337 va_start (args , format );
38+ #if defined(_MSC_VER )
39+ result = _vsnprintf_s (buffer , count , _TRUNCATE , format , args );
40+ #else
4441 result = _vsnprintf (buffer , count , format , args );
42+ #endif
4543 va_end (args );
4644 /* In the case where the string entirely filled the buffer, _vsnprintf will
4745 not null-terminate it, but snprintf must. */
@@ -52,23 +50,23 @@ static int wtf_snprintf(char *buffer, size_t count, const char *format, ...) {
5250
5351static int wtf_vsnprintf (char * buffer , size_t count , const char * format ,
5452 va_list args ) {
55- int result = _vsnprintf (buffer , count , format , args );
53+ int result ;
54+ #if defined(_MSC_VER )
55+ result = _vsnprintf_s (buffer , count , _TRUNCATE , format , args );
56+ #else
57+ result = _vsnprintf (buffer , count , format , args );
58+ #endif
5659 /* In the case where the string entirely filled the buffer, _vsnprintf will
5760 not null-terminate it, but vsnprintf must. */
5861 if (count > 0 )
5962 buffer [count - 1 ] = '\0' ;
6063 return result ;
6164}
6265
63- /* Work around a difference in Microsoft's implementation of vsnprintf, where
64- vsnprintf does not null terminate the buffer. WebKit can rely on the null
65- termination. Microsoft's implementation is fixed in VS 2015. */
6666#define vsnprintf (buffer , count , format , args ) \
6767 wtf_vsnprintf(buffer, count, format, args)
6868#define snprintf wtf_snprintf
6969
70- #endif /* OLD_MSVC */
71-
7270#endif /* !HAVE_SNPRINTF_H */
7371
7472#ifndef HAVE_STRNCASECMP_H
0 commit comments