From 75611997f9c66d67faf6f909e37262c7cfb1e4c0 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 12 Mar 2016 11:46:31 -0800 Subject: [PATCH] sort: Fix -c option In eb9bda878736344d1bef06d42e57e96de542a663, 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. --- sort.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sort.c b/sort.c index 5cfe801..90ee911 100644 --- a/sort.c +++ b/sort.c @@ -210,10 +210,15 @@ check(FILE *fp, const char *fname) { static struct line prev, cur, tmp; static size_t prevsize, cursize, tmpsize; + ssize_t len; - if (!prev.data && (prev.len = getline(&prev.data, &prevsize, fp)) < 0) - eprintf("getline:"); - while ((cur.len = getline(&cur.data, &cursize, fp)) > 0) { + if (!prev.data) { + if ((len = getline(&prev.data, &prevsize, fp)) < 0) + eprintf("getline:"); + prev.len = len; + } + while ((len = getline(&cur.data, &cursize, fp)) > 0) { + cur.len = len; if (uflag > slinecmp(&cur, &prev)) { if (!Cflag) { weprintf("disorder %s: ", fname);