From: Eric S. Raymond Date: Sat, 3 Mar 2012 16:43:46 +0000 (-0500) Subject: splint cleanup detected a bug in signal setup. X-Git-Tag: 1.6~1 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0ecdb76b0884f12f77dc4cb422f75e6d622bec8f;p=showkey.git splint cleanup detected a bug in signal setup. --- diff --git a/Makefile b/Makefile index 3eeefb1..77df453 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ clean: rm -f showkey showkey.o showkey.1 *.tar.gz rm -f MANIFEST SHIPPER.* +splint: + splint +posixlib +charintliteral +charint showkey.c + install: showkey.1 cp showkey /usr/bin/showkey cp showkey.1 /usr/share/man/man1 diff --git a/showkey.c b/showkey.c index fe9006a..51f5e10 100644 --- a/showkey.c +++ b/showkey.c @@ -33,18 +33,18 @@ static void catcher(const int sig) #define STARTCOOKIE '<' #define ENDCOOKIE '>' -void visualize(int c, char *buf) +static void visualize(int c, /*@out@*/char *buf) { char *end; bool unprintable; buf[0] = '\0'; - if (c & ALT) { + if ((c & ALT) != 0) { unprintable = true; c &=~ ALT; buf[0] = STARTCOOKIE; buf[1] = '\0'; - strcat(buf, "ALT-"); + (void) strcat(buf, "ALT-"); } if (c <= ' ') { @@ -54,17 +54,17 @@ void visualize(int c, char *buf) *end++ = STARTCOOKIE; *end++ = '\0'; } if (c > 0 && c < 27) { - strcat(buf, "CTL-"); + (void) strcat(buf, "CTL-"); end = buf + strlen(buf); *end++ = (c + 0x40); *end++ = '='; *end = 0; } - strcat(buf, lowchars[c]); + (void) strcat(buf, lowchars[c]); } else if (c == 0x3F) { unprintable = true; - strcat(buf, "DEL"); + (void) strcat(buf, "DEL"); } else { unprintable = false; buf[0] = c; @@ -83,11 +83,13 @@ main() { struct termios cooked, raw; unsigned char c; - unsigned int i, timeouts; + int i; char intrchar[32], quitchar[32]; + /*@-unrecog@*/ for (i = SIGHUP; i <= SIGIO; i++) - (void) signal(c, catcher); + (void) signal(i, catcher); + /*@=unrecog@*/ // Get the state of the tty (void) tcgetattr(0, &cooked); @@ -105,11 +107,11 @@ main() (void) printf("Terminate with your shell interrupt %s or quit %s character.\n", intrchar, quitchar); signalled = 0; - while (!signalled) + while (signalled == 0) { char cbuf[32]; - read(0, &c, 1); + (void)read(0, &c, 1); visualize(c, cbuf); (void)fputs(cbuf, stdout); (void) fflush(stdout); @@ -118,6 +120,7 @@ main() (void) printf("\nBye...\n"); // Restore the cooked state (void) tcsetattr(0, TCSANOW, &cooked); + exit(0); } /* showkey.c ends here */