From 536893c22fb446b220fb11bd4f6b8ffc79377467 Mon Sep 17 00:00:00 2001 From: valord577 Date: Wed, 15 Feb 2023 19:31:39 +0800 Subject: [PATCH] make code readable and change var name Signed-off-by: valord577 --- library/debug.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/library/debug.c b/library/debug.c index 09a1d9efd..b146e76c0 100644 --- a/library/debug.c +++ b/library/debug.c @@ -68,7 +68,11 @@ void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level, va_list argp; char str[DEBUG_BUF_SIZE]; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - int newline = -1; + int eol = -1; + +#if defined(static_assert) + static_assert(DEBUG_BUF_SIZE >= 2) +#endif if (NULL == ssl || NULL == ssl->conf || @@ -81,23 +85,21 @@ void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level, ret = mbedtls_vsnprintf(str, DEBUG_BUF_SIZE, format, argp); va_end(argp); - if (DEBUG_BUF_SIZE >= 2) { - if (ret < 0) { - newline = 0; - } else { - newline = ret; - if (ret >= DEBUG_BUF_SIZE - 1) { - newline = DEBUG_BUF_SIZE - 2; - } + if (ret < 0) { + eol= 0; + } else { + eol= ret; + if (ret >= DEBUG_BUF_SIZE - 1) { + eol = DEBUG_BUF_SIZE - 2; } } /* * Send if str contains '\n'. */ - if (newline >= 0) { - str[newline] = '\n'; - str[newline + 1] = '\0'; + if (eol >= 0) { + str[eol] = '\n'; + str[eol + 1] = '\0'; debug_send_line(ssl, level, file, line, str); }