From 931e0f2a708965001857d60cedf1b1940389cbe6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 5 Jan 2012 09:26:32 +0100 Subject: split: avoid failure due to leftover 'errno' value * src/split.c (lines_chunk_split): Fix logic bug that led to unwarranted failure of "split -n l/2 /dev/zero" on NetBSD 5.1. The same would happen when splitting a growing file, where open/lseek-end gives one size, but by the time we read, there is more data available. (bytes_chunk_extract): Likewise. * NEWS (Bug fixes): Mention this. * tests/split/l-chunk: The latter case was not exercised. Add code to do that. Bug introduced with the chunk-selecting feature in v8.7-25-gbe10739. Co-authored-by: Jim Meyering --- src/split.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/split.c') diff --git a/src/split.c b/src/split.c index 5b00fe804..2eb343b15 100644 --- a/src/split.c +++ b/src/split.c @@ -623,11 +623,11 @@ lines_chunk_split (uintmax_t k, uintmax_t n, char *buf, size_t bufsize, { char *bp = buf, *eob; size_t n_read = full_read (STDIN_FILENO, buf, bufsize); - n_read = MIN (n_read, file_size - n_written); if (n_read < bufsize && errno) error (EXIT_FAILURE, errno, "%s", infile); else if (n_read == 0) break; /* eof. */ + n_read = MIN (n_read, file_size - n_written); chunk_truncated = false; eob = buf + n_read; @@ -718,11 +718,11 @@ bytes_chunk_extract (uintmax_t k, uintmax_t n, char *buf, size_t bufsize, while (start < end) { size_t n_read = full_read (STDIN_FILENO, buf, bufsize); - n_read = MIN (n_read, end - start); if (n_read < bufsize && errno) error (EXIT_FAILURE, errno, "%s", infile); else if (n_read == 0) break; /* eof. */ + n_read = MIN (n_read, end - start); if (full_write (STDOUT_FILENO, buf, n_read) != n_read && ! ignorable (errno)) error (EXIT_FAILURE, errno, "%s", quote ("-")); -- cgit v1.2.3-54-g00ecf