1
0
mirror of synced 2026-10-24 00:28:57 +03:00

Clarify comment on base64_encode accumulator signedness

This commit is contained in:
yhirose
2026-07-01 20:12:44 -04:00
parent a7b886b9cb
commit 0ae93881b4

View File

@@ -4665,8 +4665,10 @@ inline std::string base64_encode(const std::string &in) {
std::string out;
out.reserve(in.size());
// Unsigned: once four bytes are folded in the top bit is set, so the next
// `val << 8` would left-shift a negative int (undefined behaviour).
// Unsigned: the accumulator is never masked, so with a signed int the
// `val << 8` below overflows once enough bytes are folded in (undefined
// behaviour before C++20). Only the low bits are ever emitted, so the
// wrap-around of an unsigned accumulator does not affect the output.
uint32_t val = 0;
auto valb = -6;