From f659d2cd40b92a4cbc20a7402e86f1a9e7b36326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 26 Jun 2015 17:45:00 +0200 Subject: [PATCH] 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). --- library/platform.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/platform.c b/library/platform.c index 23dba94f5d..0606214b3b 100644 --- a/library/platform.c +++ b/library/platform.c @@ -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 );