mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-17 10:59:39 +00:00
Clarify comment on base64_encode accumulator signedness
This commit is contained in:
1 parent
a7b886b9cb
commit
0ae93881b4
1 file changed
+4
-2
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user