We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a7b886b commit 0ae9388Copy full SHA for 0ae9388
1 file changed
httplib.h
@@ -4665,8 +4665,10 @@ inline std::string base64_encode(const std::string &in) {
4665
std::string out;
4666
out.reserve(in.size());
4667
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).
+ // Unsigned: the accumulator is never masked, so with a signed int the
+ // `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.
4672
uint32_t val = 0;
4673
auto valb = -6;
4674
0 commit comments