From f26560794e5f0868c9a5035158b69f3c4af8f7b3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 6 May 2022 08:04:23 -0700 Subject: Removal of dubious addch(line, 0) caused crash. It was a hack to make sure an object is allocated for a null line. --- pw.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pw.c') 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++) -- cgit v1.2.3