lib/getrange.c: getrange(): Small refactor

All 3 non-error paths in the second part resulted in *has_min = true.
Set in once before the switch(), to simplify.

This means we set this variable on error, which we didn't do before,
but since we return -1 on error and ignore (don't use) the pointees at
call site, that's fine.

Also, move a couple of *has_max = true statements to before a comment,
in preparation for future commits.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-05-04 17:22:57 -05:00
committed by Serge Hallyn
parent 6bf5d6d4f3
commit 38a0b0a610
+3 -5
View File
@@ -47,20 +47,20 @@ getrange(const char *range,
n = strtoul_noneg(&range[1], &endptr, 10);
if (('\0' != *endptr) || (0 != errno))
return -1;
*has_max = true;
/* -<long> */
*has_max = true;
*max = n;
} else {
errno = 0;
n = strtoul_noneg(range, &endptr, 10);
if (endptr == range || 0 != errno)
return -1;
*has_min = true;
switch (*endptr) {
case '\0':
/* <long> */
*has_min = true;
*has_max = true;
*min = n;
*max = n;
@@ -69,20 +69,18 @@ getrange(const char *range,
endptr++;
if ('\0' == *endptr) {
/* <long>- */
*has_min = true;
*min = n;
} else if (!isdigit (*endptr)) {
return -1;
} else {
*has_min = true;
*min = n;
errno = 0;
n = strtoul_noneg(endptr, &endptr, 10);
if ('\0' != *endptr || 0 != errno)
return -1;
*has_max = true;
/* <long>-<long> */
*has_max = true;
*max = n;
}
break;