Module Name: src
Committed By: rillig
Date: Sun May 12 18:49:36 UTC 2024
Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: cksnprintb.c decl.c emit1.c err.c lex.c
src/usr.bin/xlint/lint2: chk.c emit2.c read.c
src/usr.bin/xlint/xlint: xlint.c
Log Message:
lint: add wrapper for <ctype.h> functions, for strict bool mode
When using the Clang preprocessor (with MKLLVM=yes), the preprocessor
output does not indicate which tokens come from a system header and
which tokens come from the user code. Lint's strict bool mode relies on
this information to treat the character classification functions from
<ctype.h> as if their return type were bool instead of int.
These wrapper functions are only used when their argument is indeed a
'char', but not when the argument might be 'EOF or representable as an
unsigned char', such as when reading a byte from the input.
To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.402 -r1.403 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.243 -r1.244 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/xlint/xlint/xlint.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/common/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.49 src/usr.bin/xlint/common/lint.h:1.50
--- src/usr.bin/xlint/common/lint.h:1.49 Sat Mar 2 09:32:18 2024
+++ src/usr.bin/xlint/common/lint.h Sun May 12 18:49:35 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint.h,v 1.49 2024/03/02 09:32:18 rillig Exp $ */
+/* $NetBSD: lint.h,v 1.50 2024/05/12 18:49:35 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -160,4 +160,46 @@ typedef struct lint2_type type_t;
#endif
#endif
+static inline bool
+ch_isalnum(char ch)
+{
+ return isalnum((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isalpha(char ch)
+{
+ return isalpha((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isdigit(char ch)
+{
+ return isdigit((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_islower(char ch)
+{
+ return islower((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isprint(char ch)
+{
+ return isprint((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isspace(char ch)
+{
+ return isspace((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isupper(char ch)
+{
+ return isupper((unsigned char)ch) != 0;
+}
+
#include "externs.h"
Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.14 src/usr.bin/xlint/lint1/cksnprintb.c:1.15
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.14 Fri Apr 12 05:44:38 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $ */
+/* $NetBSD: cksnprintb.c,v 1.15 2024/05/12 18:49:36 rillig Exp $ */
/*-
* Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.15 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <stdbool.h>
@@ -86,9 +86,9 @@ check_hex_escape(const buffer *buf, quot
bool upper = false;
bool lower = false;
for (size_t i = it.start + 2; i < it.end; i++) {
- if (isupper((unsigned char)buf->data[i]))
+ if (ch_isupper(buf->data[i]))
upper = true;
- if (islower((unsigned char)buf->data[i]))
+ if (ch_islower(buf->data[i]))
lower = true;
}
if (upper && lower)
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.402 src/usr.bin/xlint/lint1/decl.c:1.403
--- src/usr.bin/xlint/lint1/decl.c:1.402 Sat May 4 06:52:16 2024
+++ src/usr.bin/xlint/lint1/decl.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.402 2024/05/04 06:52:16 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.403 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.402 2024/05/04 06:52:16 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.403 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1808,7 +1808,7 @@ check_extern_declaration(const sym_t *sy
dcs->d_redeclared_symbol == NULL &&
ends_with(curr_pos.p_file, ".c") &&
allow_c90 &&
- !isdigit((unsigned char)sym->s_name[0]) && /* see mktempsym */
+ !ch_isdigit(sym->s_name[0]) && /* see mktempsym */
strcmp(sym->s_name, "main") != 0) {
/* missing%s header declaration for '%s' */
warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'",
@@ -2906,7 +2906,7 @@ check_variable_usage(bool novar, const s
lint_assert(block_level != 0);
/* example at file scope: int c = ({ return 3; }); */
- if (sym->s_block_level == 0 && isdigit((unsigned char)sym->s_name[0]))
+ if (sym->s_block_level == 0 && ch_isdigit(sym->s_name[0]))
return;
/* errors in expressions easily cause lots of these warnings */
Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.94 src/usr.bin/xlint/lint1/emit1.c:1.95
--- src/usr.bin/xlint/lint1/emit1.c:1.94 Wed Mar 27 20:09:43 2024
+++ src/usr.bin/xlint/lint1/emit1.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.94 2024/03/27 20:09:43 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.95 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.94 2024/03/27 20:09:43 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.95 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <stdlib.h>
@@ -187,7 +187,7 @@ outsym(const sym_t *sym, scl_t sc, def_t
*/
if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
return;
- if (isdigit((unsigned char)sym->s_name[0])) /* see mktempsym */
+ if (ch_isdigit(sym->s_name[0])) /* see mktempsym */
return;
outint(csrc_pos.p_line);
@@ -393,7 +393,7 @@ static void
outqchar(char c)
{
- if (isprint((unsigned char)c) && c != '\\' && c != '"' && c != '\'') {
+ if (ch_isprint(c) && c != '\\' && c != '"' && c != '\'') {
outchar(c);
return;
}
@@ -467,7 +467,7 @@ outfstrg(const char *cp)
}
/* numeric field width */
- while (isdigit((unsigned char)c)) {
+ while (ch_isdigit(c)) {
outchar(c);
c = *cp++;
}
@@ -480,7 +480,7 @@ outfstrg(const char *cp)
outchar(c);
c = *cp++;
} else {
- while (isdigit((unsigned char)c)) {
+ while (ch_isdigit(c)) {
outchar(c);
c = *cp++;
}
@@ -534,7 +534,7 @@ outfstrg(const char *cp)
void
outusg(const sym_t *sym)
{
- if (isdigit((unsigned char)sym->s_name[0])) /* see mktempsym */
+ if (ch_isdigit(sym->s_name[0])) /* see mktempsym */
return;
outint(csrc_pos.p_line);
Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.243 src/usr.bin/xlint/lint1/err.c:1.244
--- src/usr.bin/xlint/lint1/err.c:1.243 Sat May 11 15:53:38 2024
+++ src/usr.bin/xlint/lint1/err.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.243 2024/05/11 15:53:38 rillig Exp $ */
+/* $NetBSD: err.c,v 1.244 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.243 2024/05/11 15:53:38 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.244 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <limits.h>
@@ -450,7 +450,7 @@ suppress_messages(const char *p)
{
char *end;
- for (; isdigit((unsigned char)*p); p = end + 1) {
+ for (; ch_isdigit(*p); p = end + 1) {
unsigned long id = strtoul(p, &end, 10);
if ((*end != '\0' && *end != ',') ||
id >= sizeof(msgs) / sizeof(msgs[0]) ||
@@ -771,7 +771,7 @@ enable_queries(const char *p)
{
char *end;
- for (; isdigit((unsigned char)*p); p = end + 1) {
+ for (; ch_isdigit(*p); p = end + 1) {
unsigned long id = strtoul(p, &end, 10);
if ((*end != '\0' && *end != ',') ||
id >= sizeof(queries) / sizeof(queries[0]) ||
Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.227 src/usr.bin/xlint/lint1/lex.c:1.228
--- src/usr.bin/xlint/lint1/lex.c:1.227 Sun May 12 09:07:41 2024
+++ src/usr.bin/xlint/lint1/lex.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.227 2024/05/12 09:07:41 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.228 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.227 2024/05/12 09:07:41 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.228 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <ctype.h>
@@ -896,7 +896,7 @@ check_quoted(const buffer *buf, bool com
warning(264);
else {
unsigned char ch = buf->data[it.end - 1];
- if (isprint(ch))
+ if (ch_isprint(ch))
/* dubious escape \%c */
warning(79, ch);
else
@@ -1029,11 +1029,11 @@ parse_line_directive_flags(const char *p
*is_system = false;
while (*p != '\0') {
- while (isspace((unsigned char)*p))
+ while (ch_isspace(*p))
p++;
const char *word = p;
- while (*p != '\0' && !isspace((unsigned char)*p))
+ while (*p != '\0' && !ch_isspace(*p))
p++;
size_t len = (size_t)(p - word);
@@ -1077,9 +1077,9 @@ lex_directive(const char *text)
while (*p == ' ' || *p == '\t')
p++;
- if (!isdigit((unsigned char)*p)) {
+ if (!ch_isdigit(*p)) {
if (strncmp(p, "pragma", 6) == 0
- && isspace((unsigned char)p[6]))
+ && ch_isspace(p[6]))
return;
goto error;
}
@@ -1164,19 +1164,19 @@ lex_comment(void)
bool seen_end_of_comment = false;
- while (c = read_byte(), isspace(c))
+ while (c = read_byte(), isspace(c) != 0)
continue;
/* Read the potential keyword to keywd */
size_t l = 0;
while (c != EOF && l < sizeof(keywd) - 1 &&
- (isalpha(c) || isspace(c))) {
- if (islower(c) && l > 0 && isupper((unsigned char)keywd[0]))
+ (isalpha(c) != 0 || isspace(c) != 0)) {
+ if (islower(c) != 0 && l > 0 && ch_isupper(keywd[0]))
break;
keywd[l++] = (char)c;
c = read_byte();
}
- while (l > 0 && isspace((unsigned char)keywd[l - 1]))
+ while (l > 0 && ch_isspace(keywd[l - 1]))
l--;
keywd[l] = '\0';
@@ -1188,14 +1188,14 @@ lex_comment(void)
goto skip_rest;
found_keyword:
- while (isspace(c))
+ while (isspace(c) != 0)
c = read_byte();
/* read the argument, if the keyword accepts one and there is one */
char arg[32];
l = 0;
if (keywtab[i].arg) {
- while (isdigit(c) && l < sizeof(arg) - 1) {
+ while (isdigit(c) != 0 && l < sizeof(arg) - 1) {
arg[l++] = (char)c;
c = read_byte();
}
@@ -1203,7 +1203,7 @@ found_keyword:
arg[l] = '\0';
int a = l != 0 ? atoi(arg) : -1;
- while (isspace(c))
+ while (isspace(c) != 0)
c = read_byte();
seen_end_of_comment = c == '*' && (c = read_byte()) == '/';
Index: src/usr.bin/xlint/lint2/chk.c
diff -u src/usr.bin/xlint/lint2/chk.c:1.66 src/usr.bin/xlint/lint2/chk.c:1.67
--- src/usr.bin/xlint/lint2/chk.c:1.66 Sat Mar 2 09:32:18 2024
+++ src/usr.bin/xlint/lint2/chk.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: chk.c,v 1.66 2024/03/02 09:32:18 rillig Exp $ */
+/* $NetBSD: chk.c,v 1.67 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: chk.c,v 1.66 2024/03/02 09:32:18 rillig Exp $");
+__RCSID("$NetBSD: chk.c,v 1.67 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <ctype.h>
@@ -642,9 +642,9 @@ printflike(const hte_t *hte, fcall_t *ca
}
/* field width */
- if (isdigit((unsigned char)fc)) {
+ if (ch_isdigit(fc)) {
fwidth = true;
- do { fc = *fp++; } while (isdigit((unsigned char)fc));
+ do { fc = *fp++; } while (ch_isdigit(fc));
} else if (fc == '*') {
fwidth = true;
fc = *fp++;
@@ -661,10 +661,10 @@ printflike(const hte_t *hte, fcall_t *ca
if (fc == '.') {
fc = *fp++;
prec = true;
- if (isdigit((unsigned char)fc)) {
+ if (ch_isdigit(fc)) {
do {
fc = *fp++;
- } while (isdigit((unsigned char)fc));
+ } while (ch_isdigit(fc));
} else if (fc == '*') {
fc = *fp++;
if ((tp = *ap++) == NULL) {
@@ -846,9 +846,9 @@ scanflike(const hte_t *hte, fcall_t *cal
fc = *fp++;
}
- if (isdigit((unsigned char)fc)) {
+ if (ch_isdigit(fc)) {
fwidth = true;
- do { fc = *fp++; } while (isdigit((unsigned char)fc));
+ do { fc = *fp++; } while (ch_isdigit(fc));
}
if (fc == 'h') {
Index: src/usr.bin/xlint/lint2/emit2.c
diff -u src/usr.bin/xlint/lint2/emit2.c:1.38 src/usr.bin/xlint/lint2/emit2.c:1.39
--- src/usr.bin/xlint/lint2/emit2.c:1.38 Sat Mar 2 09:32:19 2024
+++ src/usr.bin/xlint/lint2/emit2.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit2.c,v 1.38 2024/03/02 09:32:19 rillig Exp $ */
+/* $NetBSD: emit2.c,v 1.39 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: emit2.c,v 1.38 2024/03/02 09:32:19 rillig Exp $");
+__RCSID("$NetBSD: emit2.c,v 1.39 2024/05/12 18:49:36 rillig Exp $");
#endif
#include "lint2.h"
@@ -60,7 +60,7 @@ outtype(type_t *tp)
tspec_t ts = tp->t_tspec;
if (ts == INT && tp->t_is_enum)
ts = ENUM;
- if (!isupper((unsigned char)tt[ts]))
+ if (!ch_isupper(tt[ts]))
errx(1, "internal error: outtype(%d)", ts);
if (tp->t_const)
outchar('c');
Index: src/usr.bin/xlint/lint2/read.c
diff -u src/usr.bin/xlint/lint2/read.c:1.91 src/usr.bin/xlint/lint2/read.c:1.92
--- src/usr.bin/xlint/lint2/read.c:1.91 Sat Mar 2 09:32:19 2024
+++ src/usr.bin/xlint/lint2/read.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.91 2024/03/02 09:32:19 rillig Exp $ */
+/* $NetBSD: read.c,v 1.92 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: read.c,v 1.91 2024/03/02 09:32:19 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.92 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <ctype.h>
@@ -692,7 +692,7 @@ inptype(const char *cp, const char **epp
break;
case FUNC:
c = *cp;
- if (isdigit((unsigned char)c)) {
+ if (ch_isdigit(c)) {
if (!osdef)
tp->t_proto = true;
narg = parse_int(&cp);
@@ -881,7 +881,7 @@ gettlen(const char *cp, const char **epp
break;
case FUNC:
c = *cp;
- if (isdigit((unsigned char)c)) {
+ if (ch_isdigit(c)) {
narg = parse_int(&cp);
for (i = 0; i < narg; i++) {
if (i == narg - 1 && *cp == 'E')
@@ -1091,7 +1091,7 @@ inpname(const char *cp, const char **epp
buf = xrealloc(buf, blen = len + 1);
for (i = 0; i < len; i++) {
c = *cp++;
- if (!isalnum((unsigned char)c) && c != '_')
+ if (!ch_isalnum(c) && c != '_')
inperr("not alnum or _: %c", c);
buf[i] = c;
}
Index: src/usr.bin/xlint/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.124 src/usr.bin/xlint/xlint/xlint.c:1.125
--- src/usr.bin/xlint/xlint/xlint.c:1.124 Sun May 12 18:00:59 2024
+++ src/usr.bin/xlint/xlint/xlint.c Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.124 2024/05/12 18:00:59 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.125 2024/05/12 18:49:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: xlint.c,v 1.124 2024/05/12 18:00:59 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.125 2024/05/12 18:49:36 rillig Exp $");
#endif
#include <sys/param.h>
@@ -257,7 +257,7 @@ static bool
is_safe_shell(char ch)
{
- return isalnum((unsigned char)ch)
+ return ch_isalnum(ch)
|| ch == '%' || ch == '+' || ch == ',' || ch == '-' || ch == '.'
|| ch == '/' || ch == ':' || ch == '=' || ch == '@' || ch == '_';
}