fix base64 crash
All checks were successful
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 1m42s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m39s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 3m0s

This commit is contained in:
tqcq 2024-03-29 17:03:45 +08:00
parent 69d6b80638
commit f3555ec520

View File

@ -40,7 +40,8 @@ Base64::Encode(const uint8_t *ptr, size_t len)
{ {
// std::stringstream ss; // std::stringstream ss;
std::string result(EncodedLength(len), 0); auto encoded_length = EncodedLength(len);
std::string result(encoded_length, 0);
int write_idx = 0; int write_idx = 0;
int value = 0; int value = 0;
@ -67,7 +68,7 @@ Base64::Encode(const uint8_t *ptr, size_t len)
// ss << kBase64Chars[((value << 8) >> (value_bits + 2)) & 0x3F]; // ss << kBase64Chars[((value << 8) >> (value_bits + 2)) & 0x3F];
} }
// while (ss.str().size() % 4) { ss << '='; } // while (ss.str().size() % 4) { ss << '='; }
while (write_idx % 4) { result[write_idx++] = '='; } while (write_idx < encoded_length) { result[write_idx++] = '='; }
// return ss.str(); // return ss.str();
return std::move(result); return std::move(result);