From: Alejandro Colomar Date: Thu, 11 Jan 2024 17:11:13 +0000 (+0100) Subject: lib/idmapping.c: get_map_ranges(): Simplify iterator variables X-Git-Tag: 4.17.0-rc1~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c46c6a6e5a3a51b583469fa3e02c0c8e73fab219;p=thirdparty%2Fshadow.git lib/idmapping.c: get_map_ranges(): Simplify iterator variables Merge two iterator variables into one, and reduce its scope. Signed-off-by: Alejandro Colomar --- diff --git a/lib/idmapping.c b/lib/idmapping.c index b91076474..5c2fe5d32 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -27,10 +27,10 @@ #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)