mirror of
https://github.com/coreutils/coreutils.git
synced 2024-11-27 03:44:26 +08:00
od: prefer xpalloc to x2nrealloc
* src/od.c (n_specs, n_specs_allocated, write_block, get_lcm, main): Use idx_t instead of size_t for some sizes, so that we can use xpalloc. (decode_format_string): Prefer xpalloc to X2NREALLOC.
This commit is contained in:
parent
7572abed94
commit
a824f50d96
21
src/od.c
21
src/od.c
@ -259,10 +259,10 @@ static bool abbreviate_duplicate_blocks = true;
|
||||
static struct tspec *spec;
|
||||
|
||||
/* The number of format specs. */
|
||||
static size_t n_specs;
|
||||
static idx_t n_specs;
|
||||
|
||||
/* The allocated length of SPEC. */
|
||||
static size_t n_specs_allocated;
|
||||
static idx_t n_specs_allocated;
|
||||
|
||||
/* The number of input bytes formatted per output line. It must be
|
||||
a multiple of the least common multiple of the sizes associated with
|
||||
@ -1039,7 +1039,7 @@ decode_format_string (char const *s)
|
||||
char const *next;
|
||||
|
||||
if (n_specs_allocated <= n_specs)
|
||||
spec = X2NREALLOC (spec, &n_specs_allocated);
|
||||
spec = xpalloc (spec, &n_specs_allocated, 1, -1, sizeof *spec);
|
||||
|
||||
if (! decode_one_format (s_orig, s, &next, &spec[n_specs]))
|
||||
return false;
|
||||
@ -1261,7 +1261,7 @@ write_block (uintmax_t current_offset, size_t n_bytes,
|
||||
else
|
||||
{
|
||||
prev_pair_equal = false;
|
||||
for (size_t i = 0; i < n_specs; i++)
|
||||
for (idx_t i = 0; i < n_specs; i++)
|
||||
{
|
||||
int datum_width = width_bytes[spec[i].size];
|
||||
int fields_per_block = bytes_per_block / datum_width;
|
||||
@ -1374,7 +1374,7 @@ get_lcm (void)
|
||||
{
|
||||
int l_c_m = 1;
|
||||
|
||||
for (size_t i = 0; i < n_specs; i++)
|
||||
for (idx_t i = 0; i < n_specs; i++)
|
||||
l_c_m = lcm (l_c_m, width_bytes[spec[i].size]);
|
||||
return l_c_m;
|
||||
}
|
||||
@ -1623,7 +1623,6 @@ int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int n_files;
|
||||
size_t i;
|
||||
int l_c_m;
|
||||
idx_t desired_width IF_LINT ( = 0);
|
||||
bool modern = false;
|
||||
@ -1644,7 +1643,7 @@ main (int argc, char **argv)
|
||||
|
||||
atexit (close_stdout);
|
||||
|
||||
for (i = 0; i <= MAX_INTEGRAL_TYPE_SIZE; i++)
|
||||
for (idx_t i = 0; i <= MAX_INTEGRAL_TYPE_SIZE; i++)
|
||||
integral_type_size[i] = NO_SIZE;
|
||||
|
||||
integral_type_size[sizeof (char)] = CHAR;
|
||||
@ -1657,7 +1656,7 @@ main (int argc, char **argv)
|
||||
integral_type_size[sizeof (unsigned_long_long_int)] = LONG_LONG;
|
||||
#endif
|
||||
|
||||
for (i = 0; i <= MAX_FP_TYPE_SIZE; i++)
|
||||
for (idx_t i = 0; i <= MAX_FP_TYPE_SIZE; i++)
|
||||
fp_type_size[i] = NO_SIZE;
|
||||
|
||||
#if FLOAT16_SUPPORTED
|
||||
@ -2008,14 +2007,14 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Compute padding necessary to align output block. */
|
||||
for (i = 0; i < n_specs; i++)
|
||||
for (idx_t i = 0; i < n_specs; i++)
|
||||
{
|
||||
int fields_per_block = bytes_per_block / width_bytes[spec[i].size];
|
||||
int block_width = (spec[i].field_width + 1) * fields_per_block;
|
||||
if (width_per_block < block_width)
|
||||
width_per_block = block_width;
|
||||
}
|
||||
for (i = 0; i < n_specs; i++)
|
||||
for (idx_t i = 0; i < n_specs; i++)
|
||||
{
|
||||
int fields_per_block = bytes_per_block / width_bytes[spec[i].size];
|
||||
int block_width = spec[i].field_width * fields_per_block;
|
||||
@ -2024,7 +2023,7 @@ main (int argc, char **argv)
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("lcm=%d, width_per_block=%zu\n", l_c_m, width_per_block);
|
||||
for (i = 0; i < n_specs; i++)
|
||||
for (idx_t i = 0; i < n_specs; i++)
|
||||
{
|
||||
int fields_per_block = bytes_per_block / width_bytes[spec[i].size];
|
||||
affirm (bytes_per_block % width_bytes[spec[i].size] == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user