From 0ae93881b44bf94437843403bfcdc4f50445992e Mon Sep 17 00:00:00 2001 From: yhirose Date: Wed, 1 Jul 2026 20:12:44 -0400 Subject: [PATCH] Clarify comment on base64_encode accumulator signedness --- httplib.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/httplib.h b/httplib.h index 8221eeb6..1b7dd6c8 100644 --- a/httplib.h +++ b/httplib.h @@ -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;