From 925a72628b226203e94400da8d43889003804eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 29 Jun 2015 19:06:14 +0200 Subject: [PATCH] Avoid formatting debug message uselessly --- include/polarssl/debug.h | 7 ++++++- library/debug.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/polarssl/debug.h b/include/polarssl/debug.h index 2dd89a227..406cfa8be 100644 --- a/include/polarssl/debug.h +++ b/include/polarssl/debug.h @@ -57,7 +57,10 @@ #define SSL_DEBUG_MSG( level, args ) \ - debug_print_msg_free( ssl, level, __FILE__, __LINE__, debug_fmt args ); + do { \ + if( level <= debug_threshold ) \ + debug_print_msg_free( ssl, level, __FILE__, __LINE__, debug_fmt args ); \ + } while( 0 ) #define SSL_DEBUG_RET( level, text, ret ) \ debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret ); @@ -147,6 +150,8 @@ void debug_print_crt( const ssl_context *ssl, int level, const char *text, const x509_crt *crt ); #endif +extern int debug_threshold; + #ifdef __cplusplus } #endif diff --git a/library/debug.c b/library/debug.c index 753fc0faa..d23e87b91 100644 --- a/library/debug.c +++ b/library/debug.c @@ -55,7 +55,7 @@ #define DEBUG_BUF_SIZE 512 static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE; -static int debug_threshold = 0; +int debug_threshold = 0; void debug_set_log_mode( int log_mode ) { @@ -73,7 +73,7 @@ char *debug_fmt( const char *format, ... ) char *str = polarssl_malloc( DEBUG_BUF_SIZE ); if( str == NULL ) - return; + return( NULL ); va_start( argp, format ); vsnprintf( str, DEBUG_BUF_SIZE - 1, format, argp );