[hackers] [sbase] Respect exit status in grep(1) || sin

From: <git_AT_suckless.org>
Date: Fri, 21 Nov 2014 12:44:14 +0100

commit 2b39f2067530db39d4da70b8fde71a6923269136
Author: sin <sin_AT_2f30.org>
Date: Fri Nov 21 11:43:53 2014 +0000

    Respect exit status in grep(1)

diff --git a/grep.c b/grep.c
index d74f2fc..5aa5816 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -160,16 +160,22 @@ addpattern(const char *pattern)
                         pattern = ".";
 
         if (!Fflag && xflag) {
- tmp = emalloc(strlen(pattern) + 3);
+ tmp = malloc(strlen(pattern) + 3);
+ if (!tmp)
+ enprintf(Error, "malloc:");
                 snprintf(tmp, strlen(pattern) + 3, "%s%s%s",
                          pattern[0] == '^' ? "" : "^",
                          pattern,
                          pattern[strlen(pattern) - 1] == '$' ? "" : "$");
         } else {
- tmp = estrdup(pattern);
+ tmp = strdup(pattern);
+ if (!tmp)
+ enprintf(Error, "strdup:");
         }
 
- pnode = emalloc(sizeof(*pnode));
+ pnode = malloc(sizeof(*pnode));
+ if (!pnode)
+ enprintf(Error, "malloc:");
         pnode->pattern = tmp;
         SLIST_INSERT_HEAD(&phead, pnode, entry);
 }
_AT_@ -186,6 +192,8 @@ addpatternfile(FILE *fp)
                 addpattern(buf);
         }
         free(buf);
+ if (ferror(fp))
+ enprintf(Error, "read error:");
 }
 
 static int
Received on Fri Nov 21 2014 - 12:44:14 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 21 2014 - 12:48:09 CET