From: Paul Eggert Date: Wed, 25 Jun 2025 03:01:04 +0000 (-0700) Subject: od: don’t assume no holes in wide unsigned X-Git-Tag: v9.8~280 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dbe4e2f42830fd5f90391472802309bbc9d1a8ef;p=thirdparty%2Fcoreutils.git od: don’t assume no holes in wide unsigned Also, fix minor related typos. * src/od.c (MAX_INTEGRAL_TYPE_SIZE, MAX_ADDRESS_LENGTH): Now a constant, not a macro. (MAX_INTEGRAL_TYPE_WIDTH): New constant. Use it instead of CHAR_BIT, so as not to assume that uintmax_t and unsigned long long int are hole-free. This doesn’t matter on practical porting targets, though there is still a mainframe or two that have holes. (FMT_BYTES_ALLOCATED): Fix typo by changing "jd" to "jo". Fix off-by-one typo in static assertion. --- diff --git a/src/od.c b/src/od.c index c1cdd310a4..8781a2258b 100644 --- a/src/od.c +++ b/src/od.c @@ -92,7 +92,8 @@ enum output_format CHARACTER }; -#define MAX_INTEGRAL_TYPE_SIZE sizeof (unsigned long long int) +enum { MAX_INTEGRAL_TYPE_SIZE = sizeof (unsigned long long int) }; +enum { MAX_INTEGRAL_TYPE_WIDTH = ULLONG_WIDTH }; /* The maximum number of bytes needed for a format string, including the trailing nul. Each format string expects a variable amount of @@ -104,13 +105,13 @@ enum (sizeof "%*.99" + 1 + MAX (sizeof "ld", MAX (sizeof "jd", - MAX (sizeof "jd", + MAX (sizeof "jo", MAX (sizeof "ju", sizeof "jx"))))) }; /* Ensure that our choice for FMT_BYTES_ALLOCATED is reasonable. */ -static_assert (MAX_INTEGRAL_TYPE_SIZE * CHAR_BIT / 3 <= 99); +static_assert (MAX_INTEGRAL_TYPE_WIDTH <= 3 * 99); /* Each output format specification (from '-t spec' or from old-style options) is represented by one of these structures. */ @@ -202,8 +203,7 @@ static int address_base; /* The number of octal digits required to represent the largest address value. */ -#define MAX_ADDRESS_LENGTH \ - ((sizeof (uintmax_t) * CHAR_BIT + CHAR_BIT - 1) / 3) +enum { MAX_ADDRESS_LENGTH = UINTMAX_WIDTH / 3 + (UINTMAX_WIDTH % 3 != 0) }; /* Width of a normal address. */ static int address_pad_len;