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.
This commit is contained in:
parent
8d28ab70b3
commit
035a448da0
|
@ -416,18 +416,19 @@ string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize)
|
|||
*/
|
||||
std::pair<unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encodedStr, const std::uint32_t strSize)
|
||||
{
|
||||
if (!strSize) {
|
||||
return std::make_pair(std::make_unique<std::uint8_t[]>(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<std::uint8_t[]>(decodedSize);
|
||||
auto *iter = buffer.get() - 1;
|
||||
|
|
Loading…
Reference in New Issue