]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/getrange.c: getrange(): Small refactor
authorAlejandro Colomar <alx@kernel.org>
Mon, 15 Apr 2024 09:32:39 +0000 (11:32 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 4 May 2024 22:22:57 +0000 (17:22 -0500)
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>
lib/getrange.c

index 5c0767c6f7e4e58af9f0f2a66e7df7ec5c422be8..b12cb72aa62cb49ad2dd661550966a1782e68bd1 100644 (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;