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.
This commit is contained in:
rillig 2021-07-25 22:43:08 +00:00
parent 7ed694cb89
commit 52d0684901
3 changed files with 48 additions and 40 deletions

View File

@ -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 isxdigit(int);
int tolower(int);
int toupper(int);
int is_other(int);
int to_other(int);
void sink(int);
void
@ -60,6 +63,10 @@ cover_is_ctype_function(char c)
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

View File

@ -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]

View File

@ -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 @@ static bool
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