]> thyrsus.com Git - showkey.git/commitdiff
splint cleanup detected a bug in signal setup.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 3 Mar 2012 16:43:46 +0000 (11:43 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 3 Mar 2012 16:43:46 +0000 (11:43 -0500)
Makefile
showkey.c

index 3eeefb11f32369986aa5ba07ab995ca71757a472..77df4532ffcf35a8790b754e4cafcc3adfa87f37 100644 (file)
--- 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
index fe9006a25300eadb405dad5de2eed6514dea26e3..51f5e108b926b8ef4843c93a10b0285585b5001b 100644 (file)
--- 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 */