]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
split: fix failure for certain number of specified files
authorPádraig Brady <P@draigBrady.com>
Sat, 8 Jun 2019 21:49:01 +0000 (22:49 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 8 Jun 2019 21:58:01 +0000 (22:58 +0100)
* 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

NEWS
THANKS.in
src/split.c
tests/split/suffix-auto-length.sh

diff --git a/NEWS b/NEWS
index 593c69b00d5b8151b33766c8615112d69717cd08..5b132484097fea3d7a265bf9d8e181ce6d83e981 100644 (file)
--- 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]
 
index 3951b66d69905b7135404af82fb95ea2fd25dbff..02b8ada1c537e38003a168c567147e850d95fb70 100644 (file)
--- 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
index 30fdb4462669f40682ac1fced12b41282a55c24c..aea20e5d24c1557b464e43f602398b5565655d4f 100644 (file)
@@ -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
index e5594d878161503000420d744a8d491a474bbac9..487e54e675bfe4c932aa21e89624e8a8f0f5f06d 100755 (executable)
@@ -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