Declare mbedtls_debug_print_msg as printf-like
We were not getting any warnings on printf format errors, as we do not explicitly use printf anywhere in the code. Thankfully there is a way to mark a function as having printf behaviour so that its inputs can be checked in the same way as printf would be. Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
ea32d55623
commit
4e589701d8
2 changed files with 21 additions and 1 deletions
|
@ -80,6 +80,25 @@
|
||||||
|
|
||||||
#endif /* MBEDTLS_DEBUG_C */
|
#endif /* MBEDTLS_DEBUG_C */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \def MBEDTLS_PRINTF_ATTRIBUTE
|
||||||
|
*
|
||||||
|
* Mark a function as having printf attributes, and thus enable checking
|
||||||
|
* via -wFormat and other flags. This does nothing in windows builds as the
|
||||||
|
* windows compiler does not support it.
|
||||||
|
*
|
||||||
|
* Module: library/debug.c
|
||||||
|
* Caller:
|
||||||
|
*
|
||||||
|
* This module provides debugging functions.
|
||||||
|
*/
|
||||||
|
#if (defined(_WIN32) || defined(_WIN64))
|
||||||
|
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
|
||||||
|
__attribute__((format (printf, string_index, first_to_check)))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -118,7 +137,7 @@ void mbedtls_debug_set_threshold( int threshold );
|
||||||
*/
|
*/
|
||||||
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||||
const char *file, int line,
|
const char *file, int line,
|
||||||
const char *format, ... );
|
const char *format, ... ) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Print the return value of a function to the debug output. This
|
* \brief Print the return value of a function to the debug output. This
|
||||||
|
|
|
@ -74,6 +74,7 @@ static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MBEDTLS_PRINTF_ATTRIBUTE(5, 6)
|
||||||
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||||
const char *file, int line,
|
const char *file, int line,
|
||||||
const char *format, ... )
|
const char *format, ... )
|
||||||
|
|
Loading…
Reference in a new issue