]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/getrange.c: getrange(): Small refactor
authorAlejandro Colomar <alx@kernel.org>
Mon, 15 Apr 2024 09:18:46 +0000 (11:18 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 4 May 2024 22:22:57 +0000 (17:22 -0500)
Set *has_{min,max} = false at the begining, so we only need to set them
to true later.

This means we set these variables 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.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/getrange.c

index 03b0a91397c982b759f1815ced6d926d9d9f7e5b..5c0767c6f7e4e58af9f0f2a66e7df7ec5c422be8 100644 (file)
@@ -36,6 +36,9 @@ getrange(const char *range,
        if (NULL == range)
                return -1;
 
+       *has_min = false;
+       *has_max = false;
+
        if ('-' == range[0]) {
                if (!isdigit(range[1]))
                        return -1;
@@ -46,7 +49,6 @@ getrange(const char *range,
                        return -1;
 
                /* -<long> */
-               *has_min = false;
                *has_max = true;
                *max = n;
        } else {
@@ -68,7 +70,6 @@ getrange(const char *range,
                        if ('\0' == *endptr) {
                                /* <long>- */
                                *has_min = true;
-                               *has_max = false;
                                *min = n;
                        } else if (!isdigit (*endptr)) {
                                return -1;