From c9522fb740200ccef6230cec452c48efb31e5394 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 11 May 2023 22:05:17 +0200 Subject: Removed all Printf-family functions from StringUtils. Replaced them with fmt::format calls, including changes to the format strings. Also changed the format strings to use FMT_STRING, so that the format is checked compile-time against the arguments. Also fixed code-style violations already present in the code. --- src/mbedTLS++/BlockingSslClientSocket.cpp | 14 +++++++------- src/mbedTLS++/Sha1Checksum.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/mbedTLS++') diff --git a/src/mbedTLS++/BlockingSslClientSocket.cpp b/src/mbedTLS++/BlockingSslClientSocket.cpp index bc9d07157..6e6410879 100644 --- a/src/mbedTLS++/BlockingSslClientSocket.cpp +++ b/src/mbedTLS++/BlockingSslClientSocket.cpp @@ -137,7 +137,7 @@ bool cBlockingSslClientSocket::Connect(const AString & a_ServerName, UInt16 a_Po if (ret != 0) { - Printf(m_LastErrorText, "SSL initialization failed: -0x%x", -ret); + m_LastErrorText = fmt::format(FMT_STRING("SSL initialization failed: -0x{:x}"), -ret); return false; } @@ -150,7 +150,7 @@ bool cBlockingSslClientSocket::Connect(const AString & a_ServerName, UInt16 a_Po ret = m_Ssl.Handshake(); if (ret != 0) { - Printf(m_LastErrorText, "SSL handshake failed: -0x%x", -ret); + m_LastErrorText = fmt::format(FMT_STRING("SSL handshake failed: -0x{:x}"), -ret); return false; } @@ -169,8 +169,8 @@ void cBlockingSslClientSocket::SetExpectedPeerName(AString a_ExpectedPeerName) if (!m_ExpectedPeerName.empty()) { LOGWARNING( - "SSL: Trying to set multiple expected peer names, only the last one will be used. Name: %s", - a_ExpectedPeerName.c_str() + "SSL: Trying to set multiple expected peer names, only the last one will be used. %s overwriting the previous %s", + a_ExpectedPeerName, m_ExpectedPeerName ); } @@ -216,7 +216,7 @@ bool cBlockingSslClientSocket::Send(const void * a_Data, size_t a_NumBytes) { ASSERT(res != MBEDTLS_ERR_SSL_WANT_READ); // This should never happen with callback-based SSL ASSERT(res != MBEDTLS_ERR_SSL_WANT_WRITE); // This should never happen with callback-based SSL - Printf(m_LastErrorText, "Data cannot be written to SSL context: -0x%x", -res); + m_LastErrorText = fmt::format(FMT_STRING("Data cannot be written to SSL context: -0x{:x}"), -res); return false; } else @@ -241,7 +241,7 @@ int cBlockingSslClientSocket::Receive(void * a_Data, size_t a_MaxBytes) int res = m_Ssl.ReadPlain(a_Data, a_MaxBytes); if (res < 0) { - Printf(m_LastErrorText, "Data cannot be read form SSL context: -0x%x", -res); + m_LastErrorText = fmt::format(FMT_STRING("Data cannot be read from SSL context: -0x{:x}"), -res); } return res; } @@ -250,7 +250,7 @@ int cBlockingSslClientSocket::Receive(void * a_Data, size_t a_MaxBytes) -void cBlockingSslClientSocket::Disconnect(void) +void cBlockingSslClientSocket::Disconnect() { // Ignore if not connected if (!m_IsConnected) diff --git a/src/mbedTLS++/Sha1Checksum.cpp b/src/mbedTLS++/Sha1Checksum.cpp index 8ed7976ae..4c4c92298 100644 --- a/src/mbedTLS++/Sha1Checksum.cpp +++ b/src/mbedTLS++/Sha1Checksum.cpp @@ -91,7 +91,7 @@ void cSha1Checksum::DigestToHex(const Checksum & a_Digest, AString & a_Out) a_Out.reserve(40); for (int i = 0; i < 20; i++) { - AppendPrintf(a_Out, "%x", a_Digest[i]); + a_Out.append(fmt::format(FMT_STRING("{:02x}"), a_Digest[i])); } } @@ -123,7 +123,7 @@ void cSha1Checksum::DigestToJava(const Checksum & a_Digest, AString & a_Out) a_Out.reserve(40); for (int i = 0; i < 20; i++) { - AppendPrintf(a_Out, "%02x", Digest[i]); + a_Out.append(fmt::format(FMT_STRING("{:02x}"), Digest[i])); } while ((a_Out.length() > 0) && (a_Out[0] == '0')) { -- cgit v1.2.3