mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-20 18:56:39 +02:00
split: fix failure for certain number of specified files
* src/split.c (set_suffix_length): Use a more standard zero based logN calculation for the number of units. * tests/split/suffix-auto-length.sh: Add a test case. * THANKS.in: Mention the reporter. * NEWS: Mention the fix. Fixes https://bugs.gnu.org/35291
This commit is contained in:
5
NEWS
5
NEWS
@@ -29,6 +29,11 @@ GNU coreutils NEWS -*- outline -*-
|
||||
(like Solaris 10 and Solaris 11).
|
||||
[bug introduced in coreutils-8.31]
|
||||
|
||||
split no longer reports a "output file suffixes exhausted" error
|
||||
when the specified number of files is evenly divisible by 10, 16, 26,
|
||||
for --numeric, --hex, or default alphabetic suffixes respectively.
|
||||
[bug introduced in coreutils-8.24]
|
||||
|
||||
|
||||
* Noteworthy changes in release 8.31 (2019-03-10) [stable]
|
||||
|
||||
|
||||
@@ -311,6 +311,7 @@ Joerg Sonnenberger joerg@britannica.bec.de
|
||||
Joey Hess joeyh@debian.org
|
||||
Johan Boule bohan@bohan.dyndns.org
|
||||
Johan Danielsson joda@pdc.kth.se
|
||||
Johannes Altmanninger aclopte@gmail.com
|
||||
John Bley jbb6@acpub.duke.edu
|
||||
John Gatewood Ham zappaman@alphabox.compsci.buu.ac.th
|
||||
John Gotts jgotts@umich.edu
|
||||
|
||||
18
src/split.c
18
src/split.c
@@ -164,7 +164,7 @@ set_suffix_length (uintmax_t n_units, enum Split_type split_type)
|
||||
{
|
||||
#define DEFAULT_SUFFIX_LENGTH 2
|
||||
|
||||
uintmax_t suffix_needed = 0;
|
||||
uintmax_t suffix_length_needed = 0;
|
||||
|
||||
/* The suffix auto length feature is incompatible with
|
||||
a user specified start value as the generated suffixes
|
||||
@@ -176,7 +176,7 @@ set_suffix_length (uintmax_t n_units, enum Split_type split_type)
|
||||
if (split_type == type_chunk_bytes || split_type == type_chunk_lines
|
||||
|| split_type == type_rr)
|
||||
{
|
||||
uintmax_t n_units_end = n_units;
|
||||
uintmax_t n_units_end = n_units - 1;
|
||||
if (numeric_suffix_start)
|
||||
{
|
||||
uintmax_t n_start;
|
||||
@@ -194,26 +194,26 @@ set_suffix_length (uintmax_t n_units, enum Split_type split_type)
|
||||
|
||||
}
|
||||
size_t alphabet_len = strlen (suffix_alphabet);
|
||||
bool alphabet_slop = (n_units_end % alphabet_len) != 0;
|
||||
while (n_units_end /= alphabet_len)
|
||||
suffix_needed++;
|
||||
suffix_needed += alphabet_slop;
|
||||
do
|
||||
suffix_length_needed++;
|
||||
while (n_units_end /= alphabet_len);
|
||||
|
||||
suffix_auto = false;
|
||||
}
|
||||
|
||||
if (suffix_length) /* set by user */
|
||||
{
|
||||
if (suffix_length < suffix_needed)
|
||||
if (suffix_length < suffix_length_needed)
|
||||
{
|
||||
die (EXIT_FAILURE, 0,
|
||||
_("the suffix length needs to be at least %"PRIuMAX),
|
||||
suffix_needed);
|
||||
suffix_length_needed);
|
||||
}
|
||||
suffix_auto = false;
|
||||
return;
|
||||
}
|
||||
else
|
||||
suffix_length = MAX (DEFAULT_SUFFIX_LENGTH, suffix_needed);
|
||||
suffix_length = MAX (DEFAULT_SUFFIX_LENGTH, suffix_length_needed);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -50,4 +50,10 @@ rm -f x*
|
||||
# as that would result in an incorrect order for the total output file set
|
||||
returns_ 1 split --numeric-suffixes=100 --number=r/100 file.in || fail=1
|
||||
|
||||
# coreutils v8.24 - v8.31 inclusive would incorrectly auto calculate
|
||||
# a suffix length that was too small, when the number of files was
|
||||
# evenly divisible by the suffix base (10,16,26).
|
||||
truncate -s0 file.in || framework_failure_
|
||||
split --numeric-suffixes --number=110 file.in || fail=1
|
||||
|
||||
Exit $fail
|
||||
|
||||
Reference in New Issue
Block a user