[hackers] [sbase] sort: Fix -c option || Michael Forney

From: <git_AT_suckless.org>
Date: Sun, 13 Mar 2016 12:08:41 +0100 (CET)

commit 75611997f9c66d67faf6f909e37262c7cfb1e4c0
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sat Mar 12 11:46:31 2016 -0800
Commit: sin <sin_AT_2f30.org>
CommitDate: Sun Mar 13 11:08:36 2016 +0000

    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.

diff --git a/sort.c b/sort.c
index 5cfe801..90ee911 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -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);
Received on Sun Mar 13 2016 - 12:08:41 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 13 2016 - 12:12:24 CET