On 01/05/2012 02:32 AM, Bruno Haible wrote: >> http://meyering.net/cu/coreutils-8.14.116-1e18d.tar.xz > > On NetBSD 5.1/x86, I get this test failure in particular: > > > FAIL: split/l-chunk > =================== > split: /dev/zero: No such file or directory > stat: cannot stat `x*': No such file or directory > rm: cannot remove `x??': No such file or directory > > > The first among these messages comes from this command: > $ ./split -n l/2 /dev/zero > ./split: /dev/zero: No such file or directory > > Single-stepping it, it gets to call > lines_chunk_split (k=0, n=2, buf=0x7f7ffda01000 "", bufsize=65536, > file_size=2) > and at split.c:625 the call > full_read (STDIN_FILENO, buf, bufsize) > returns 65536, the same value as bufsize. The code in line 627 is buggy: > It uses errno even when full_read returned bufsize. But that value is > undefined. > > This patch fixes the bug and make the test succeed:
Nice one Bruno, thanks! > 2012-01-04 Bruno Haible <[email protected]> > > split: Avoid failure due to leftover 'errno' value. > * src/split.c (lines_chunk_split): Fix logic. > > --- src/split.c.bak 2012-01-05 03:03:16.000000000 +0100 > +++ src/split.c 2012-01-05 03:25:31.000000000 +0100 > @@ -623,11 +623,11 @@ > { > 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; Hmm, I wonder should full_read() be adjusting the errno? I.E. maybe the behavior of read() and full_read() should be different, as the latter can do a successful partial read(), and then have a failure. So it should be possible to assume n_read >-1 and a valid errno? Anyway I'm rushing now, so I'll look at this later. cheers, Pádraig.
