split: avoid apparent infloop when splitting /dev/zero w/-n on the Hurd
authorJim Meyering <meyering@redhat.com>
Mon, 7 May 2012 07:32:00 +0000 (09:32 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 8 May 2012 16:32:58 +0000 (18:32 +0200)
* src/split.c (main): Use stat.st_size only for regular files.
Samuel Thibault reported in http://bugs.gnu.org/11424 that the
/dev/zero-splitting tests would appear to infloop on GNU/Hurd,
because /dev/zero's st_size is LONG_MAX.  It was only a problem
when using the --number (-n) option.
* NEWS (Bug fixes): Mention it.
This bug was introduced with the --number option, via
commit v8.7-25-gbe10739

NEWS
src/split.c

diff --git a/NEWS b/NEWS
index 2dc6531..eb95404 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   was particularly easy to trigger, since there, the removal of D could
   precede the initial stat.  [This bug was present in "the beginning".]
 
+  split --number=C /dev/null no longer appears to infloop on GNU/Hurd
+  [bug introduced in coreutils-8.8]
+
 ** New features
 
   fmt now accepts the --goal=WIDTH (-g) option.
index 99f6390..062aede 100644 (file)
@@ -1339,7 +1339,9 @@ main (int argc, char **argv)
     error (EXIT_FAILURE, errno, "%s", infile);
   if (in_blk_size == 0)
     in_blk_size = io_blksize (stat_buf);
-  file_size = stat_buf.st_size;
+
+  /* stat.st_size is valid only for regular files.  For others, use 0.  */
+  file_size = S_ISREG (stat_buf.st_mode) ? stat_buf.st_size : 0;
 
   if (split_type == type_chunk_bytes || split_type == type_chunk_lines)
     {