From: Jim Meyering Date: Mon, 14 Jan 2002 08:36:48 +0000 (+0000) Subject: (mergefps): Fix bug when eliminating empty files. X-Git-Tag: TEXTUTILS-2_0_20~111 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=98ad58770935ae5bc084e196871a3c7d0741c623;p=thirdparty%2Fcoreutils.git (mergefps): Fix bug when eliminating empty files. --- diff --git a/src/sort.c b/src/sort.c index 3b3bbccb76..52942279d7 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1648,28 +1648,28 @@ mergefps (char **files, register int nfiles, saved.text = NULL; /* Read initial lines from each input file. */ - for (i = 0; i < nfiles; ++i) + for (i = 0; i < nfiles; ) { fps[i] = xfopen (files[i], "r"); initbuf (&buffer[i], sizeof (struct line), MAX (merge_buffer_size, sort_size / nfiles)); - /* If a file is empty, eliminate it from future consideration. */ - while (i < nfiles && !fillbuf (&buffer[i], fps[i], files[i])) + if (fillbuf (&buffer[i], fps[i], files[i])) + { + struct line const *linelim = buffer_linelim (&buffer[i]); + cur[i] = linelim - 1; + base[i] = linelim - buffer[i].nlines; + i++; + } + else { + /* fps[i] is empty; eliminate it from future consideration. */ xfclose (fps[i], files[i]); zaptemp (files[i]); + free (buffer[i].buf); --nfiles; for (j = i; j < nfiles; ++j) files[j] = files[j + 1]; } - if (i == nfiles) - free (buffer[i].buf); - else - { - struct line const *linelim = buffer_linelim (&buffer[i]); - cur[i] = linelim - 1; - base[i] = linelim - buffer[i].nlines; - } } if (! ofp)