From 38f102e2e7bc3d472ec0a9bb6d26e365ca8ef530 Mon Sep 17 00:00:00 2001 From: synqa Date: Fri, 30 Jan 2026 14:42:32 +0900 Subject: [PATCH] Fix undefined behavior of left shift Left shifting UCHAR promotes it to a signed integer. When the value is >= 128 and shifted by 24, the result sets the sign bit, causing undefined behavior. Fixes it by explicit casting to UINT. --- src/Mayaqua/Encrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mayaqua/Encrypt.c b/src/Mayaqua/Encrypt.c index e9b8b745..c52ed16a 100644 --- a/src/Mayaqua/Encrypt.c +++ b/src/Mayaqua/Encrypt.c @@ -4761,7 +4761,7 @@ static void MY_SHA0_Transform(MY_SHA0_CTX* ctx) { UCHAR* p = ctx->buf; int t; for(t = 0; t < 16; ++t) { - UINT tmp = *p++ << 24; + UINT tmp = (UINT)*p++ << 24; tmp |= *p++ << 16; tmp |= *p++ << 8; tmp |= *p++;