commit 392e5b3d5157fbffb6c2aee3f09c967a9a4bd1ee
parent 808f813803796bd9b75fbce47d1453d1f8a79f25
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)