X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=main.c;h=062f9d7557b8d3c8828bfd5dc16de9864faa019e;hb=35e96b8deba8aae863cef32f2ea2a84ebf162472;hp=750366e7cfb8f031ebaae4e77fb8f2c6c5223e56;hpb=478f6f95f1cb349e93bfe49ae6721c222c3a1a6d;p=dwm.git diff --git a/main.c b/main.c index 750366e..062f9d7 100644 --- a/main.c +++ b/main.c @@ -227,6 +227,7 @@ xerror(Display *dpy, XErrorEvent *ee) { int main(int argc, char *argv[]) { + char *p; int r, xfd; fd_set rd; @@ -270,21 +271,24 @@ main(int argc, char *argv[]) { if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { if(errno == EINTR) continue; - else - eprint("select failed\n"); + eprint("select failed\n"); } if(FD_ISSET(STDIN_FILENO, &rd)) { - switch(r = read(STDIN_FILENO, stext, sizeof(stext))) { + switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) { case -1: - strncpy(stext, strerror(errno), sizeof(stext)); + strncpy(stext, strerror(errno), sizeof stext - 1); + stext[sizeof stext - 1] = '\0'; readin = False; break; case 0: - strncpy(stext, "EOF", sizeof(stext)); + strncpy(stext, "EOF", 4); readin = False; break; default: - stext[r-1] = 0; + for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0'); + for(p = stext + strlen(stext) - 1; p >= stext && *p != '\n'; --p); + if(p > stext) + strncpy(stext, p + 1, sizeof stext); } drawstatus(); }