From: Paul Eggert Date: Thu, 7 Nov 2024 22:17:14 +0000 (-0800) Subject: cut,numfmt: prefer xpalloc to x2nrealloc X-Git-Tag: v9.6~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3aaadf281f63c766a8c439b1ba5df5848d1c8b25;p=thirdparty%2Fcoreutils.git cut,numfmt: prefer xpalloc to x2nrealloc * src/set-fields.c (n_frp, n_frp_allocated, complement_rp, set_fields): Prefer idx_t to ptrdiff_t/size_t for nonnegative sizes. (add_range_pair): Use xpalloc, not x2nrealloc. --- diff --git a/src/set-fields.c b/src/set-fields.c index 0cf1ef247d..6102282eaf 100644 --- a/src/set-fields.c +++ b/src/set-fields.c @@ -27,10 +27,10 @@ struct field_range_pair *frp; /* Number of finite ranges specified by the user. */ -size_t n_frp; +idx_t n_frp; /* Number of `struct field_range_pair's allocated. */ -static size_t n_frp_allocated; +static idx_t n_frp_allocated; #define FATAL_ERROR(Message) \ do \ @@ -47,7 +47,7 @@ static void add_range_pair (uintmax_t lo, uintmax_t hi) { if (n_frp == n_frp_allocated) - frp = X2NREALLOC (frp, &n_frp_allocated); + frp = xpalloc (frp, &n_frp_allocated, 1, -1, sizeof *frp); frp[n_frp].lo = lo; frp[n_frp].hi = hi; ++n_frp; @@ -70,7 +70,7 @@ static void complement_rp (void) { struct field_range_pair *c = frp; - size_t n = n_frp; + idx_t n = n_frp; frp = nullptr; n_frp = 0; @@ -79,7 +79,7 @@ complement_rp (void) if (c[0].lo > 1) add_range_pair (1, c[0].lo - 1); - for (size_t i = 1; i < n; ++i) + for (idx_t i = 1; i < n; ++i) { if (c[i - 1].hi + 1 == c[i].lo) continue; @@ -250,9 +250,8 @@ set_fields (char const *fieldstr, unsigned int options) { /* In case the user specified -c$(echo 2^64|bc),22, complain only about the first number. */ - /* Determine the length of the offending number. */ - size_t len = strspn (num_start, "0123456789"); - char *bad_num = ximemdup0 (num_start, len); + char *bad_num = ximemdup0 (num_start, + strspn (num_start, "0123456789")); error (0, 0, (options & SETFLD_ERRMSG_USE_POS) ?_("byte/character offset %s is too large") :_("field number %s is too large"), @@ -281,9 +280,9 @@ set_fields (char const *fieldstr, unsigned int options) qsort (frp, n_frp, sizeof (frp[0]), compare_ranges); /* Merge range pairs (e.g. `2-5,3-4' becomes `2-5'). */ - for (size_t i = 0; i < n_frp; ++i) + for (idx_t i = 0; i < n_frp; ++i) { - for (size_t j = i + 1; j < n_frp; ++j) + for (idx_t j = i + 1; j < n_frp; ++j) { if (frp[j].lo <= frp[i].hi) { diff --git a/src/set-fields.h b/src/set-fields.h index 4d09038058..ec36f28f7e 100644 --- a/src/set-fields.h +++ b/src/set-fields.h @@ -27,7 +27,7 @@ struct field_range_pair extern struct field_range_pair *frp; /* Number of finite ranges specified by the user. */ -extern size_t n_frp; +extern idx_t n_frp; /* field list parsing options */ enum