]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/idmapping.c: get_map_ranges(): Simplify iterator variables
authorAlejandro Colomar <alx@kernel.org>
Thu, 11 Jan 2024 17:11:13 +0000 (18:11 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 12 Jul 2024 03:42:58 +0000 (22:42 -0500)
Merge two iterator variables into one, and reduce its scope.

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

index b910764746c438c40b026b0cb8f13204af568389..5c2fe5d327fea4c46adcc5168bb8a5cdbfc5bdab 100644 (file)
 #include "sizeof.h"
 
 
-struct map_range *get_map_ranges(int ranges, int argc, char **argv)
+struct map_range *
+get_map_ranges(int ranges, int argc, char **argv)
 {
-       struct map_range *mappings, *m;
-       int idx, argidx;
+       struct map_range  *mappings, *m;
 
        if (ranges < 0 || argc < 0) {
                fprintf(log_get_logfd(), "%s: error calculating number of arguments\n", log_get_progname());
@@ -51,8 +51,8 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
 
        /* Gather up the ranges from the command line */
        m = mappings;
-       for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, m++) {
-               if (a2ul(&m->upper, argv[argidx + 0], NULL, 0, 0, UINT_MAX) == -1) {
+       for (int i = 0; i < ranges * 3; i+=3, m++) {
+               if (a2ul(&m->upper, argv[i + 0], NULL, 0, 0, UINT_MAX) == -1) {
                        if (errno == ERANGE) {
                                fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
                                exit(EXIT_FAILURE);
@@ -60,7 +60,7 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
                        free(mappings);
                        return NULL;
                }
-               if (a2ul(&m->lower, argv[argidx + 1], NULL, 0, 0, UINT_MAX) == -1) {
+               if (a2ul(&m->lower, argv[i + 1], NULL, 0, 0, UINT_MAX) == -1) {
                        if (errno == ERANGE) {
                                fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
                                exit(EXIT_FAILURE);
@@ -68,7 +68,7 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
                        free(mappings);
                        return NULL;
                }
-               if (a2ul(&m->count, argv[argidx + 2], NULL, 0, 0,
+               if (a2ul(&m->count, argv[i + 2], NULL, 0, 0,
                         MIN(MIN(UINT_MAX, ULONG_MAX - 1) - m->lower,
                             MIN(UINT_MAX, ULONG_MAX - 1) - m->upper))
                    == -1)