modify library/debug.c to use polarssl_snprintf
diff --git a/library/debug.c b/library/debug.c
index f327baa..88a9dac 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -44,6 +44,12 @@
#endif
#endif /* _MSC_VER */
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_snprintf snprintf
+#endif
+
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
static int debug_threshold = 0;
@@ -86,7 +92,7 @@
return;
}
- snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
+ polarssl_snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
str[maxlen] = '\0';
ssl->f_dbg( ssl->p_dbg, level, str );
}
@@ -103,9 +109,9 @@
return;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
+ polarssl_snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
text, ret, -ret );
str[maxlen] = '\0';
@@ -124,9 +130,9 @@
return;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
+ polarssl_snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
text, (unsigned int) len );
str[maxlen] = '\0';
@@ -143,7 +149,7 @@
{
if( i > 0 )
{
- snprintf( str + idx, maxlen - idx, " %s\n", txt );
+ polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
ssl->f_dbg( ssl->p_dbg, level, str );
idx = 0;
@@ -151,14 +157,14 @@
}
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- idx += snprintf( str + idx, maxlen - idx, "%04x: ",
+ idx += polarssl_snprintf( str + idx, maxlen - idx, "%04x: ",
(unsigned int) i );
}
- idx += snprintf( str + idx, maxlen - idx, " %02x",
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x",
(unsigned int) buf[i] );
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
}
@@ -166,9 +172,9 @@
if( len > 0 )
{
for( /* i = i */; i % 16 != 0; i++ )
- idx += snprintf( str + idx, maxlen - idx, " " );
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " " );
- snprintf( str + idx, maxlen - idx, " %s\n", txt );
+ polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
ssl->f_dbg( ssl->p_dbg, level, str );
}
}
@@ -184,11 +190,11 @@
if( ssl->f_dbg == NULL || level > debug_threshold )
return;
- snprintf( str, maxlen, "%s(X)", text );
+ polarssl_snprintf( str, maxlen, "%s(X)", text );
str[maxlen] = '\0';
debug_print_mpi( ssl, level, file, line, str, &X->X );
- snprintf( str, maxlen, "%s(Y)", text );
+ polarssl_snprintf( str, maxlen, "%s(Y)", text );
str[maxlen] = '\0';
debug_print_mpi( ssl, level, file, line, str, &X->Y );
}
@@ -215,9 +221,9 @@
break;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
+ polarssl_snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
text, (int) ( ( n * ( sizeof(t_uint) << 3 ) ) + j + 1 ) );
str[maxlen] = '\0';
@@ -240,16 +246,16 @@
{
if( j > 0 )
{
- snprintf( str + idx, maxlen - idx, "\n" );
+ polarssl_snprintf( str + idx, maxlen - idx, "\n" );
ssl->f_dbg( ssl->p_dbg, level, str );
idx = 0;
}
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
}
- idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
j++;
@@ -261,13 +267,13 @@
{
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
{
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
}
- idx += snprintf( str + idx, maxlen - idx, " 00" );
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " 00" );
}
- snprintf( str + idx, maxlen - idx, "\n" );
+ polarssl_snprintf( str + idx, maxlen - idx, "\n" );
ssl->f_dbg( ssl->p_dbg, level, str );
}
#endif /* POLARSSL_BIGNUM_C */
@@ -294,7 +300,7 @@
if( items[i].type == POLARSSL_PK_DEBUG_NONE )
return;
- snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
+ polarssl_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
name[sizeof( name ) - 1] = '\0';
if( items[i].type == POLARSSL_PK_DEBUG_MPI )
@@ -321,7 +327,7 @@
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
{
- snprintf( prefix, maxlen, "%s(%04d): ", file, line );
+ polarssl_snprintf( prefix, maxlen, "%s(%04d): ", file, line );
prefix[maxlen] = '\0';
}
else
@@ -335,9 +341,9 @@
x509_crt_info( buf, sizeof( buf ) - 1, prefix, crt );
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
+ polarssl_snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
text, ++i, buf );
str[maxlen] = '\0';