From 8f719f80b8f8b9dc128e902d1d2b94ee5c26a070 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 9 Mar 2026 17:07:53 +0000 Subject: util/nvmutil: safer calculated_checksum we rely on uint16_t wrapping, but some platforms may behave weirdly. cast as uint32_t and then cast back, on return, with an explicit mask beforehand. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index c069cc6e..d84cd1c8 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1132,12 +1132,12 @@ static uint16_t calculated_checksum(size_t p) { size_t c; - uint16_t val16 = 0; + uint32_t val16 = 0; for (c = 0; c < NVM_CHECKSUM_WORD; c++) - val16 += nvm_word(c, p); + val16 += (uint32_t)nvm_word(c, p); - return NVM_CHECKSUM - val16; + return (uint16_t)((NVM_CHECKSUM - val16) & 0xffff); } /* -- cgit v1.2.1