Fixed subtle bug in and simplified updateblock

This commit is contained in:
Ashish Kumar Yadav 2021-03-28 12:46:35 +05:30
parent dbace38b2a
commit 801a3de6d7

View file

@ -12,7 +12,7 @@
#define NILL INT_MIN #define NILL INT_MIN
#define LOCKFILE "/tmp/dwmblocks.pid" #define LOCKFILE "/tmp/dwmblocks.pid"
#define DELIMITERLENGTH sizeof delimiter #define DELIMITERLENGTH (sizeof delimiter)
#define STATUSLENGTH ((sizeof blocks / sizeof blocks[0]) * (CMDOUTLENGTH + DELIMITERLENGTH)) #define STATUSLENGTH ((sizeof blocks / sizeof blocks[0]) * (CMDOUTLENGTH + DELIMITERLENGTH))
#include "config.h" #include "config.h"
@ -213,21 +213,18 @@ updateblock(Block *block, int sigval)
exit(1); exit(1);
} }
close(fd[0]); close(fd[0]);
if (trd == 0) {
if (block->prvtext[0] != '\0') { block->curtext[trd] = '\0';
block->prvtext[0] = '\0';
if (!dirtyblock || block < dirtyblock)
dirtyblock = block;
}
block->length = 0;
} else {
if (block->curtext[trd - 1] == '\n')
trd--;
if (memcmp(block->curtext, block->prvtext, trd + 1) != 0) { if (memcmp(block->curtext, block->prvtext, trd + 1) != 0) {
memcpy(block->prvtext, block->curtext, trd + 1); memcpy(block->prvtext, block->curtext, trd + 1);
if (!dirtyblock || block < dirtyblock) if (!dirtyblock || block < dirtyblock)
dirtyblock = block; dirtyblock = block;
} }
if (trd == 0)
block->length = 0;
else {
if (block->curtext[trd - 1] == '\n')
trd--;
if (block->pathc) if (block->pathc)
block->curtext[trd++] = block->signal; block->curtext[trd++] = block->signal;
memcpy(block->curtext + trd, delimiter, DELIMITERLENGTH); memcpy(block->curtext + trd, delimiter, DELIMITERLENGTH);