commit a939a59f8b6bfd9e73ea04d19c121eaae3473fb9
parent 8d3d9bc44a7ae70fab00852a136f6b1b5e5aaa7c
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Sun, 28 Mar 2021 22:25:30 +0200

Fix empty lines not treated as empty output

Diffstat:
Mdwmblocks.c | 9++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/dwmblocks.c b/dwmblocks.c @@ -65,12 +65,11 @@ void getcmd(const Block *block, char *output) fgets(output+i, CMDLENGTH-i-delimLen, cmdf); pclose(cmdf); i = strlen(output); - if (i == 0) { - /* return if block and command output are both empty */ - return; - } i = (i && output[i-1] == '\n') ? i-1 : i; /* delete trailing newline */ - strncpy(output+i, delim, delimLen); + if (i == 0) /* ensure length 0 in case the string was "\n" */ + output[0] = '\0'; /* ensure length 0 in case the string was "\n" */ + else /* only add delimiter if output not empty */ + strncpy(output+i, delim, delimLen); } void getcmds(int time)