sort: Fix -c option

In eb9bda8787, a bug was introduced in the
handling of -1 return values from getline. Since the type of the len
field in struct line is unsigned, the break condition was never true.
This caused sort -c to never succeed.
This commit is contained in:
Michael Forney 2016-03-12 11:46:31 -08:00 committed by sin
parent d4f7ecd334
commit 75611997f9

11
sort.c
View File

@ -210,10 +210,15 @@ check(FILE *fp, const char *fname)
{ {
static struct line prev, cur, tmp; static struct line prev, cur, tmp;
static size_t prevsize, cursize, tmpsize; static size_t prevsize, cursize, tmpsize;
ssize_t len;
if (!prev.data && (prev.len = getline(&prev.data, &prevsize, fp)) < 0) if (!prev.data) {
eprintf("getline:"); if ((len = getline(&prev.data, &prevsize, fp)) < 0)
while ((cur.len = getline(&cur.data, &cursize, fp)) > 0) { eprintf("getline:");
prev.len = len;
}
while ((len = getline(&cur.data, &cursize, fp)) > 0) {
cur.len = len;
if (uflag > slinecmp(&cur, &prev)) { if (uflag > slinecmp(&cur, &prev)) {
if (!Cflag) { if (!Cflag) {
weprintf("disorder %s: ", fname); weprintf("disorder %s: ", fname);