commit 4d2bb732b7d661347ea4a25665d83723408ad325
parent 8d8ccb4b32810fec690ccb99c879c361de8c26db
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sat, 6 Sep 2025 15:17:48 +0200
mhd_str.c: improved readability of some functions
Diffstat:
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/mhd2/mhd_str.c b/src/mhd2/mhd_str.c
@@ -1528,25 +1528,28 @@ mhd_strx_to_uint32_n (const char *restrict str,
{
size_t i;
uint_fast32_t res;
- int digit;
res = 0;
i = 0;
- while (i < maxlen && (digit = xdigittovalue (str[i])) >= 0)
+ while (i < maxlen)
{
+ const int digit = xdigittovalue (str[i]);
uint_fast32_t prev_res = res;
+ if (0 > digit)
+ break;
+
res *= 16;
if (res / 16 != prev_res)
return 0;
- res += (unsigned int) digit;
- if (res < (unsigned int) digit)
+ res += (uint_fast32_t) digit;
+ if (res < (uint_fast32_t) digit)
return 0;
i++;
}
- if (i)
+ if (0 != i)
*out_val = res;
return i;
}
@@ -1594,14 +1597,17 @@ mhd_strx_to_uint64_n (const char *restrict str,
{
size_t i;
uint_fast64_t res;
- int digit;
res = 0;
i = 0;
- while (i < maxlen && (digit = xdigittovalue (str[i])) >= 0)
+ while (i < maxlen)
{
+ const int digit = xdigittovalue (str[i]);
uint_fast64_t prev_res = res;
+ if (0 > digit)
+ break;
+
res *= 16;
if (res / 16 != prev_res)
return 0;
@@ -1611,7 +1617,7 @@ mhd_strx_to_uint64_n (const char *restrict str,
i++;
}
- if (i)
+ if (0 != i)
*out_val = res;
return i;
}