aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-09-27 20:36:56 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-09-27 20:36:56 +0300
commit4153c1cd4c234226f5075e4115606d8fc4549ad4 (patch)
tree7027ae153f866f846187f502e9efe17dba104bbc
parent3cd82965442c3550a861d87e55d5ab664a579520 (diff)
downloadlibmicrohttpd-4153c1cd4c234226f5075e4115606d8fc4549ad4.tar.gz
libmicrohttpd-4153c1cd4c234226f5075e4115606d8fc4549ad4.zip
mhd_str: minor refactoring for compact code
-rw-r--r--src/microhttpd/mhd_str.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index efe31f12..9c1c5172 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1168,12 +1168,8 @@ MHD_str_to_uvalue_n_ (const char *str,
1168{ 1168{
1169 size_t i; 1169 size_t i;
1170 uint64_t res; 1170 uint64_t res;
1171 int digit;
1172 const uint64_t max_v_div_b = max_val / base; 1171 const uint64_t max_v_div_b = max_val / base;
1173 const uint64_t max_v_mod_b = max_val % base; 1172 const uint64_t max_v_mod_b = max_val % base;
1174 /* 'digit->value' must be function, not macro */
1175 int (*const dfunc)(char) = (base == 16) ?
1176 toxdigitvalue : todigitvalue;
1177 1173
1178 if (! str || ! out_val || 1174 if (! str || ! out_val ||
1179 ((base != 16) && (base != 10)) ) 1175 ((base != 16) && (base != 10)) )
@@ -1181,8 +1177,13 @@ MHD_str_to_uvalue_n_ (const char *str,
1181 1177
1182 res = 0; 1178 res = 0;
1183 i = 0; 1179 i = 0;
1184 while (maxlen > i && 0 <= (digit = dfunc (str[i]))) 1180 while (maxlen > i)
1185 { 1181 {
1182 const int digit = (base == 16) ?
1183 toxdigitvalue (str[i]) : todigitvalue (str[i]);
1184
1185 if (0 > digit)
1186 break;
1186 if ( ((max_v_div_b) < res) || 1187 if ( ((max_v_div_b) < res) ||
1187 (( (max_v_div_b) == res) && ( (max_v_mod_b) < (uint64_t) digit) ) ) 1188 (( (max_v_div_b) == res) && ( (max_v_mod_b) < (uint64_t) digit) ) )
1188 return 0; 1189 return 0;