From: Pádraig Brady Date: Sat, 8 Jun 2019 21:49:01 +0000 (+0100) Subject: split: fix failure for certain number of specified files X-Git-Tag: v8.32~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=738a746d825aff96821da535e36b0f60e7a65946;p=thirdparty%2Fcoreutils.git 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 --- diff --git a/NEWS b/NEWS index 593c69b00d..5b13248409 100644 --- a/NEWS +++ b/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] diff --git a/THANKS.in b/THANKS.in index 3951b66d69..02b8ada1c5 100644 --- a/THANKS.in +++ b/THANKS.in @@ -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 diff --git a/src/split.c b/src/split.c index 30fdb44626..aea20e5d24 100644 --- a/src/split.c +++ b/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 diff --git a/tests/split/suffix-auto-length.sh b/tests/split/suffix-auto-length.sh index e5594d8781..487e54e675 100755 --- a/tests/split/suffix-auto-length.sh +++ b/tests/split/suffix-auto-length.sh @@ -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