Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: split is_ctype_function into separ...



details:   https://anonhg.NetBSD.org/src/rev/5d0773377a67
branches:  trunk
changeset: 984861:5d0773377a67
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 25 22:43:08 2021 +0000

description:
lint: split is_ctype_function into separate parts

This reduces the number of string comparisons for function names that
start with 'is' or 'to'.

The tests now cover function names that start with 'is' or 'to' but are
not one of the well-known functions from ctype.h.  This removes the '*'
in the output from gcov.

No functional change.

diffstat:

 tests/usr.bin/xlint/lint1/msg_342.c   |   9 +++++++-
 tests/usr.bin/xlint/lint1/msg_342.exp |  40 +++++++++++++++++-----------------
 usr.bin/xlint/lint1/ckctype.c         |  39 +++++++++++++++++----------------
 3 files changed, 48 insertions(+), 40 deletions(-)

diffs (135 lines):

diff -r 7dbac30da2f0 -r 5d0773377a67 tests/usr.bin/xlint/lint1/msg_342.c
--- a/tests/usr.bin/xlint/lint1/msg_342.c       Sun Jul 25 22:31:22 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_342.c       Sun Jul 25 22:43:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_342.c,v 1.2 2021/07/25 22:31:22 rillig Exp $       */
+/*     $NetBSD: msg_342.c,v 1.3 2021/07/25 22:43:08 rillig Exp $       */
 # 3 "msg_341.c"
 
 // Test for message: argument to '%s' must be cast to 'unsigned char', not to '%s' [342]
@@ -27,6 +27,9 @@
 int tolower(int);
 int toupper(int);
 
+int is_other(int);
+int to_other(int);
+
 void sink(int);
 
 void
@@ -60,6 +63,10 @@
        tolower(c);
        /* expect+1: warning: argument to 'toupper' must be 'unsigned char' or EOF, not 'char' [341] */
        toupper(c);
+
+       /* Functions with similar names are not checked. */
+       is_other(c);
+       to_other(c);
 }
 
 void
diff -r 7dbac30da2f0 -r 5d0773377a67 tests/usr.bin/xlint/lint1/msg_342.exp
--- a/tests/usr.bin/xlint/lint1/msg_342.exp     Sun Jul 25 22:31:22 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_342.exp     Sun Jul 25 22:43:08 2021 +0000
@@ -1,20 +1,20 @@
-msg_341.c(36): warning: argument to 'isalnum' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(38): warning: argument to 'isalpha' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(40): warning: argument to 'isblank' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(42): warning: argument to 'iscntrl' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(44): warning: argument to 'isdigit' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(46): warning: argument to 'isgraph' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(48): warning: argument to 'islower' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(50): warning: argument to 'isprint' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(52): warning: argument to 'ispunct' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(54): warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(56): warning: argument to 'isupper' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(58): warning: argument to 'isxdigit' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(60): warning: argument to 'tolower' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(62): warning: argument to 'toupper' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(70): warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(79): warning: argument to 'isspace' must be cast to 'unsigned char', not to 'int' [342]
-msg_341.c(82): warning: argument to 'isspace' must be cast to 'unsigned char', not to 'unsigned int' [342]
-msg_341.c(113): warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'char' [341]
-msg_341.c(119): warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'int' [342]
-msg_341.c(122): warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'unsigned int' [342]
+msg_341.c(39): warning: argument to 'isalnum' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(41): warning: argument to 'isalpha' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(43): warning: argument to 'isblank' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(45): warning: argument to 'iscntrl' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(47): warning: argument to 'isdigit' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(49): warning: argument to 'isgraph' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(51): warning: argument to 'islower' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(53): warning: argument to 'isprint' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(55): warning: argument to 'ispunct' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(57): warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(59): warning: argument to 'isupper' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(61): warning: argument to 'isxdigit' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(63): warning: argument to 'tolower' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(65): warning: argument to 'toupper' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(77): warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(86): warning: argument to 'isspace' must be cast to 'unsigned char', not to 'int' [342]
+msg_341.c(89): warning: argument to 'isspace' must be cast to 'unsigned char', not to 'unsigned int' [342]
+msg_341.c(120): warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'char' [341]
+msg_341.c(126): warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'int' [342]
+msg_341.c(129): warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'unsigned int' [342]
diff -r 7dbac30da2f0 -r 5d0773377a67 usr.bin/xlint/lint1/ckctype.c
--- a/usr.bin/xlint/lint1/ckctype.c     Sun Jul 25 22:31:22 2021 +0000
+++ b/usr.bin/xlint/lint1/ckctype.c     Sun Jul 25 22:43:08 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckctype.c,v 1.2 2021/04/05 02:17:52 rillig Exp $ */
+/* $NetBSD: ckctype.c,v 1.3 2021/07/25 22:43:08 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckctype.c,v 1.2 2021/04/05 02:17:52 rillig Exp $");
+__RCSID("$NetBSD: ckctype.c,v 1.3 2021/07/25 22:43:08 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -56,24 +56,25 @@
 is_ctype_function(const char *name)
 {
 
-       if (name[0] != 'i' || name[1] != 's')
-               if (name[0] != 't' || name[1] != 'o')
-                       return false;
+       if (name[0] == 'i' && name[1] == 's')
+               return strcmp(name, "isalnum") == 0 ||
+                      strcmp(name, "isalpha") == 0 ||
+                      strcmp(name, "isblank") == 0 ||
+                      strcmp(name, "iscntrl") == 0 ||
+                      strcmp(name, "isdigit") == 0 ||
+                      strcmp(name, "isgraph") == 0 ||
+                      strcmp(name, "islower") == 0 ||
+                      strcmp(name, "isprint") == 0 ||
+                      strcmp(name, "ispunct") == 0 ||
+                      strcmp(name, "isspace") == 0 ||
+                      strcmp(name, "isupper") == 0 ||
+                      strcmp(name, "isxdigit") == 0;
 
-       return strcmp(name, "isalnum") == 0 ||
-              strcmp(name, "isalpha") == 0 ||
-              strcmp(name, "isblank") == 0 ||
-              strcmp(name, "iscntrl") == 0 ||
-              strcmp(name, "isdigit") == 0 ||
-              strcmp(name, "isgraph") == 0 ||
-              strcmp(name, "islower") == 0 ||
-              strcmp(name, "isprint") == 0 ||
-              strcmp(name, "ispunct") == 0 ||
-              strcmp(name, "isspace") == 0 ||
-              strcmp(name, "isupper") == 0 ||
-              strcmp(name, "isxdigit") == 0 ||
-              strcmp(name, "tolower") == 0 ||
-              strcmp(name, "toupper") == 0;
+       if (name[0] == 't' && name[1] == 'o')
+               return strcmp(name, "tolower") == 0 ||
+                      strcmp(name, "toupper") == 0;
+
+       return false;
 }
 
 static bool



Home | Main Index | Thread Index | Old Index