commit 58e2bde8f1425e45f23c5598187914335272a2b8 parent eb5524da37edb7d6046da2363efea6dbc6d8a8c1 Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev> Date: Sun, 28 Jun 2026 22:15:48 +0200 auth_digest: some code readability improvements Diffstat:
| M | src/mhd2/auth_digest.c | | | 21 | ++++++++++++++------- |
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/mhd2/auth_digest.c b/src/mhd2/auth_digest.c @@ -51,6 +51,7 @@ #include "mhd_assert.h" #include "mhd_unreachable.h" +#include "mhd_assume.h" #include <string.h> #include "sys_malloc.h" @@ -2268,16 +2269,22 @@ check_nonce_nc (struct MHD_Daemon *restrict d, ret = mhd_CHECK_NONCENC_STALE; else /* (nonce_slot->max_recvd_nc > nc) */ { - /* Out-of-order 'nc' value. Check whether was used before */ - if (64 >= nonce_slot->max_recvd_nc - nc) + /* Out-of-order 'nc' value. Check whether it was used before */ + const uint_fast32_t nc_delta = nonce_slot->max_recvd_nc - nc; + + mhd_ASSUME (0u != nc_delta); /* Guaranteed by if() branches */ + + if (64u >= nc_delta) { - if (0 == - ((UINT64_C (1) << (nonce_slot->max_recvd_nc - nc - 1)) - & nonce_slot->nmask)) + const uint_fast64_t nc_bit = (UINT64_C (1) << (nc_delta - 1)); + + mhd_ASSUME (0u != nc_bit); + mhd_ASSUME (0u != (nc_bit & UINT64_C (0xFFFFFFFFFFFFFFFF))); + + if (0u == (nc_bit & nonce_slot->nmask)) { /* 'nc' has not been used before. Set the bit. */ - nonce_slot->nmask |= - (UINT64_C (1) << (nonce_slot->max_recvd_nc - nc - 1)); + nonce_slot->nmask |= nc_bit; ret = mhd_CHECK_NONCENC_OK; } else