aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-06 08:04:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-06 08:04:23 -0700
commitf26560794e5f0868c9a5035158b69f3c4af8f7b3 (patch)
tree68292924cf674fc7c51f50a74b60c005273b4ebe /pw.c
parent1965dfa1525950cf4efc96a16613734d65ea0dc0 (diff)
downloadpw-f26560794e5f0868c9a5035158b69f3c4af8f7b3.tar.gz
pw-f26560794e5f0868c9a5035158b69f3c4af8f7b3.tar.bz2
pw-f26560794e5f0868c9a5035158b69f3c4af8f7b3.zip
Removal of dubious addch(line, 0) caused crash.
It was a hack to make sure an object is allocated for a null line.
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/pw.c b/pw.c
index 3bd77fe..f44ce2a 100644
--- a/pw.c
+++ b/pw.c
@@ -193,6 +193,13 @@ static char *dsgrow(char *str, size_t len)
return ds->str;
}
+static char *dsensure(char *str)
+{
+ if (str)
+ return str;
+ return dsgrow(0, 0);
+}
+
static char *dsdup(char *str)
{
size_t len = strlen(str);
@@ -995,6 +1002,7 @@ int main(int argc, char **argv)
clearerr(stdin);
} else if (ch == '\n') {
nfds = 1;
+ line = dsensure(line);
if ((pw.stat & stat_grep)) {
int i;
for (i = 0; i < ngrep; i++)