From 38a0b0a610cb56c24941326e1e91e119e0c4a4a1 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 15 Apr 2024 11:32:39 +0200 Subject: [PATCH] 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 --- lib/getrange.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/getrange.c b/lib/getrange.c index 5c0767c6..b12cb72a 100644 --- a/lib/getrange.c +++ b/lib/getrange.c @@ -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; /* - */ - *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': /* */ - *has_min = true; *has_max = true; *min = n; *max = n; @@ -69,20 +69,18 @@ getrange(const char *range, endptr++; if ('\0' == *endptr) { /* - */ - *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; /* - */ - *has_max = true; *max = n; } break;