Module Name:    src
Committed By:   rillig
Date:           Fri Jul  1 21:48:05 UTC 2022

Modified Files:
        src/usr.bin/xlint/lint1: err.c

Log Message:
lint: clean up suppression of warnings and errors

Since lint1.h 1.11 from 2001-12-13, lint1 had been a memory hog.  While
it used a bit set for keeping track of the message IDs of the suppressed
messages, it only used the lower 4 bits of each 32-bit word, due to a
missing CHAR_BIT in __NERRBITS.

As a quick hack, the bit set had 1024 entries, much more than the number
of actual messages, which is currently at 350.  This meant 674 bytes of
wasted memory, plus the code size for the bit manipulations.

The only functional change is that the option '-X' now only accepts
actually valid message IDs.  Previously it had accepted all numbers from
0 to 1023.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/xlint/lint1/err.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/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.178 src/usr.bin/xlint/lint1/err.c:1.179
--- src/usr.bin/xlint/lint1/err.c:1.178	Fri Jul  1 21:25:39 2022
+++ src/usr.bin/xlint/lint1/err.c	Fri Jul  1 21:48:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.178 2022/07/01 21:25:39 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.179 2022/07/01 21:48:05 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.178 2022/07/01 21:25:39 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.179 2022/07/01 21:48:05 rillig Exp $");
 #endif
 
 #include <errno.h>
@@ -408,22 +408,7 @@ static const char *const msgs[] = {
 	"non type argument to alignof is a GCC extension",	      /* 349 */
 };
 
-#define	ERR_SETSIZE	1024
-#define __NERRBITS (sizeof(unsigned int))
-
-typedef	struct err_set {
-	unsigned int	errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS];
-} err_set;
-
-#define	ERR_SET(n, p)	\
-	((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS)))
-#define	ERR_CLR(n, p)	\
-	((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS)))
-#define	ERR_ISSET(n, p)	\
-	(((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS))) != 0)
-#define	ERR_ZERO(p)	(void)memset((p), 0, sizeof(*(p)))
-
-static err_set	msgset;
+static bool	is_suppressed[sizeof(msgs) / sizeof(msgs[0])];
 
 static struct include_level {
 	const char *filename;
@@ -435,17 +420,15 @@ void
 suppress_messages(char *ids)
 {
 	char *ptr, *end;
-	long id;
+	unsigned long id;
 
 	for (ptr = strtok(ids, ","); ptr != NULL; ptr = strtok(NULL, ",")) {
 		errno = 0;
-		id = strtol(ptr, &end, 0);
-		if ((id == TARG_LONG_MIN || id == TARG_LONG_MAX) &&
-		    errno == ERANGE)
-			err(1, "invalid error message id '%s'", ptr);
-		if (*end != '\0' || ptr == end || id < 0 || id >= ERR_SETSIZE)
+		id = strtoul(ptr, &end, 0);
+		if (*end != '\0' || ptr == end ||
+		    id >= sizeof(msgs) / sizeof(msgs[0]))
 			errx(1, "invalid error message id '%s'", ptr);
-		ERR_SET(id, &msgset);
+		is_suppressed[id] = true;
 	}
 }
 
@@ -536,7 +519,7 @@ verror_at(int msgid, const pos_t *pos, v
 {
 	const	char *fn;
 
-	if (ERR_ISSET(msgid, &msgset))
+	if (is_suppressed[msgid])
 		return;
 
 	fn = lbasename(pos->p_file);
@@ -552,7 +535,7 @@ vwarning_at(int msgid, const pos_t *pos,
 {
 	const	char *fn;
 
-	if (ERR_ISSET(msgid, &msgset))
+	if (is_suppressed[msgid])
 		return;
 
 	debug_step("%s: lwarn=%d msgid=%d", __func__, lwarn, msgid);
@@ -574,7 +557,7 @@ vmessage_at(int msgid, const pos_t *pos,
 {
 	const char *fn;
 
-	if (ERR_ISSET(msgid, &msgset))
+	if (is_suppressed[msgid])
 		return;
 
 	fn = lbasename(pos->p_file);

Reply via email to