Tune up Windows snprintf() support

When we build with Visual Studio in debug mode, the invalid parameter handler
aborts the application (and offers to debug it) when n is 0. We want to
just return -1 instead (as calls with n == 0 are expected and happen in our
tests).
This commit is contained in:
Manuel Pégourié-Gonnard 2015-06-26 17:45:00 +02:00
parent fc36708697
commit f659d2cd40

View File

@ -70,6 +70,10 @@ int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
int ret;
va_list argp;
/* Avoid calling the invalid parameter handler by checking ourselves */
if( s == NULL || n == 0 || fmt == NULL )
return( -1 );
va_start( argp, fmt );
ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
va_end( argp );