Hi,
Manuel Badzong --> dwm (2006-11-26 15:19:58 +0100):
> I tried several inputs (empty lines, lines with multiple '\n', all '\n'
> lines). The following patch would handle all of them correctly. Though
> I 'm not sure if this is really necessary (but it remains one line of
> code).
I'm not sure whether dwm really should try that hard to fix the input
it is given...
However, to continue the tradition of patching the patches patch I've
attached a patch. It
- '\0'-terminates the error message if read() failed (just in case
strlen(strerror(errno)) >= sizeof stext - 1)
- saves 1020 bytes from being zeroed unnecessarily (performance! ;-))
Cheers, Jukka
--
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
diff -r 70472540c443 main.c
--- a/main.c Sun Nov 26 15:43:16 2006 +0100
+++ b/main.c Sun Nov 26 18:28:33 2006 +0100
@@ -277,10 +277,11 @@ main(int argc, char *argv[]) {
switch(r = read(STDIN_FILENO, stext, sizeof stext - 1))
{
case -1:
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: