From 035a448da000c547d7c50bcd42d713c541510122 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 1 Sep 2023 17:21:18 +0200 Subject: [PATCH] Avoid clazy warning about `decodeBase64` The warning is about invalid memory usage within the loop in case `strSize` is zero. It is supposedly not correct because then the loop would never be entered anyways in that case. However, it is likely nevertheless a good idea to silence the warning. --- conversion/stringconversion.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/conversion/stringconversion.cpp b/conversion/stringconversion.cpp index 47878d2..5f8595b 100644 --- a/conversion/stringconversion.cpp +++ b/conversion/stringconversion.cpp @@ -416,18 +416,19 @@ string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize) */ std::pair, std::uint32_t> decodeBase64(const char *encodedStr, const std::uint32_t strSize) { + if (!strSize) { + return std::make_pair(std::make_unique(0), 0); // early return to prevent clazy warning + } if (strSize % 4) { throw ConversionException("invalid size of base64"); } std::uint32_t decodedSize = (strSize / 4) * 3; const char *const end = encodedStr + strSize; - if (strSize) { - if (*(end - 1) == base64Pad) { - --decodedSize; - } - if (*(end - 2) == base64Pad) { - --decodedSize; - } + if (*(end - 1) == base64Pad) { + --decodedSize; + } + if (*(end - 2) == base64Pad) { + --decodedSize; } auto buffer = std::make_unique(decodedSize); auto *iter = buffer.get() - 1;