Fixed issue with empty command delimiter
[dwmblocks.git] / dwmblocks.c
index b6f696f..c66dbc7 100644 (file)
@@ -56,6 +56,8 @@ void getcmd(const Block *block, char *output)
        int i = strlen(block->icon);
        fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
        i = strlen(output);
+       if (i == 0)//return if block and command output are both empty
+               return;
        if (delim[0] != '\0') {
                //only chop off newline if one is present at the end
                i = output[i-1] == '\n' ? i-1 : i;
@@ -178,7 +180,8 @@ int main(int argc, char** argv)
                else if (!strcmp("-p",argv[i]))
                        writestatus = pstdout;
        }
-       delim[MIN(delimLen, strlen(delim))] = '\0';
+       delimLen = MIN(delimLen, strlen(delim));
+       delim[delimLen++] = '\0';
        signal(SIGTERM, termhandler);
        signal(SIGINT, termhandler);
        statusloop();