From d46a70b9c8b826adbe64eed624ca92b1228be4e7 Mon Sep 17 00:00:00 2001 From: mugglewei Date: Tue, 19 Sep 2023 00:26:17 +0800 Subject: [PATCH] set variable 'buffer' that in base32_decode to unsigned integer type In base32_decode, variable 'buffer' is signed integer may lead undefined behavior when left operand. --- src/base32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base32.c b/src/base32.c index 9c8e302..64c572f 100644 --- a/src/base32.c +++ b/src/base32.c @@ -20,7 +20,7 @@ #include "base32.h" int base32_decode(const uint8_t *encoded, uint8_t *result, int bufSize) { - int buffer = 0; + unsigned int buffer = 0; int bitsLeft = 0; int count = 0; for (const uint8_t *ptr = encoded; count < bufSize && *ptr; ++ptr) { @@ -68,7 +68,7 @@ int base32_encode(const uint8_t *data, int length, uint8_t *result, } int count = 0; if (length > 0) { - int buffer = data[0]; + unsigned int buffer = data[0]; int next = 1; int bitsLeft = 8; while (count < bufSize && (bitsLeft > 0 || next < length)) {