From a4f055fe0ccccea87ea924ec58c7c1de78e13444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 8 Jul 2015 16:46:13 +0200 Subject: [PATCH] Some windows environments don't have _snprint_s Do an alternative version for them. That happens for example with our windows buildbot with mingw32-make. --- library/debug.c | 9 +++++++++ library/platform.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/library/debug.c b/library/debug.c index 672e04537..2a559b54b 100644 --- a/library/debug.c +++ b/library/debug.c @@ -65,7 +65,16 @@ void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level, va_start( argp, format ); #if defined(_WIN32) +#if defined(_TRUNCATE) ret = _vsnprintf_s( str, DEBUG_BUF_SIZE, _TRUNCATE, format, argp ); +#else + ret = _vsnprintf( str, DEBUG_BUF_SIZE, format, argp ); + if( ret < 0 || (size_t) ret == DEBUG_BUF_SIZE ) + { + str[DEBUG_BUF_SIZE-1] = '\0'; + ret = -1; + } +#endif #else ret = vsnprintf( str, DEBUG_BUF_SIZE, format, argp ); #endif diff --git a/library/platform.c b/library/platform.c index 0606214b3..3161a4c00 100644 --- a/library/platform.c +++ b/library/platform.c @@ -75,7 +75,16 @@ int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... ) return( -1 ); va_start( argp, fmt ); +#if defined(_TRUNCATE) ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp ); +#else + ret = _vsnprintf( s, n, fmt, argp ); + if( ret < 0 || (size_t) ret == n ) + { + s[n-1] = '\0'; + ret = -1; + } +#endif va_end( argp ); return( ret );