Skip to content

Commit 0ae9388

Browse files
committed
Clarify comment on base64_encode accumulator signedness
1 parent a7b886b commit 0ae9388

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

httplib.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4665,8 +4665,10 @@ inline std::string base64_encode(const std::string &in) {
46654665
std::string out;
46664666
out.reserve(in.size());
46674667

4668-
// Unsigned: once four bytes are folded in the top bit is set, so the next
4669-
// `val << 8` would left-shift a negative int (undefined behaviour).
4668+
// Unsigned: the accumulator is never masked, so with a signed int the
4669+
// `val << 8` below overflows once enough bytes are folded in (undefined
4670+
// behaviour before C++20). Only the low bits are ever emitted, so the
4671+
// wrap-around of an unsigned accumulator does not affect the output.
46704672
uint32_t val = 0;
46714673
auto valb = -6;
46724674

0 commit comments

Comments
 (0)