From 2ee4d358dcbebd39e9289c3925494152a294edb5 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 13 Dec 2023 19:33:06 +0100 Subject: [PATCH] Fix 32-bit ext/hash build --- ext/hash/hash_sha.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/hash/hash_sha.c b/ext/hash/hash_sha.c index 7de00f37be4..201a8513f96 100644 --- a/ext/hash/hash_sha.c +++ b/ext/hash/hash_sha.c @@ -525,7 +525,8 @@ PHP_HASH_API void PHP_SHA384Update(PHP_SHA384_CTX * context, const unsigned char if ((context->count[0] += ((uint64_t) inputLen << 3)) < ((uint64_t) inputLen << 3)) { context->count[1]++; } - context->count[1] += (uint64_t) (inputLen >> 61); + /* The cast may seem unnecessary, but on 32-bit this makes sure the result is 0 without invoking undefined behaviour. */ + context->count[1] += (uint64_t) inputLen >> 61; partLen = 128 - index; @@ -679,7 +680,8 @@ PHP_HASH_API void PHP_SHA512Update(PHP_SHA512_CTX * context, const unsigned char if ((context->count[0] += ((uint64_t) inputLen << 3)) < ((uint64_t) inputLen << 3)) { context->count[1]++; } - context->count[1] += (uint64_t) (inputLen >> 61); + /* The cast may seem unnecessary, but on 32-bit this makes sure the result is 0 without invoking undefined behaviour. */ + context->count[1] += (uint64_t) inputLen >> 61; partLen = 128 - index;