Module Name: src
Committed By: rillig
Date: Sun Jan 8 15:22:33 UTC 2023
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_348.c
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: recognize enum constant named 'max' as a count of values
Seen in external/bsd/mdocml/dist/mdoc.h(50).
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_348.c
cvs rdiff -u -r1.486 -r1.487 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/msg_348.c
diff -u src/tests/usr.bin/xlint/lint1/msg_348.c:1.6 src/tests/usr.bin/xlint/lint1/msg_348.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_348.c:1.6 Sun Jan 8 15:18:02 2023
+++ src/tests/usr.bin/xlint/lint1/msg_348.c Sun Jan 8 15:22:33 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_348.c,v 1.6 2023/01/08 15:18:02 rillig Exp $ */
+/* $NetBSD: msg_348.c,v 1.7 2023/01/08 15:22:33 rillig Exp $ */
# 3 "msg_348.c"
// Test for message 348: maximum value %d of '%s' does not match maximum array index %d [348]
@@ -177,7 +177,6 @@ color_with_uc_count_name(enum color_with
enum uppercase_max {
M_FIRST,
M_SECOND,
- /* expect+1: previous declaration of 'M_MAX' [260] */
M_MAX
};
@@ -185,14 +184,12 @@ const char *
uppercase_max_name(enum uppercase_max x)
{
static const char *const name[] = { "first", "second" };
- /* expect+1: warning: maximum value 2 of 'enum uppercase_max' does not match maximum array index 1 [348] */
return name[x];
}
enum lowercase_max {
M_first,
M_second,
- /* expect+1: previous declaration of 'M_max' [260] */
M_max
};
@@ -200,6 +197,5 @@ const char *
lowercase_max_name(enum lowercase_max x)
{
static const char *const name[] = { "first", "second" };
- /* expect+1: warning: maximum value 2 of 'enum lowercase_max' does not match maximum array index 1 [348] */
return name[x];
}
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.486 src/usr.bin/xlint/lint1/tree.c:1.487
--- src/usr.bin/xlint/lint1/tree.c:1.486 Wed Jan 4 05:08:22 2023
+++ src/usr.bin/xlint/lint1/tree.c Sun Jan 8 15:22:33 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.487 2023/01/08 15:22:33 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.487 2023/01/08 15:22:33 rillig Exp $");
#endif
#include <float.h>
@@ -2058,12 +2058,14 @@ check_enum_array_index(const tnode_t *ln
return;
/*
- * If the largest enum constant is named '*_NUM_*', it is typically
- * not part of the allowed enum values but a marker for the number
- * of actual enum values.
+ * If the name of the largest enum constant contains 'MAX' or 'NUM',
+ * that constant is typically not part of the allowed enum values but
+ * a marker for the number of actual enum values.
*/
if (max_enum_value == max_array_index + 1 &&
- (strstr(max_ec->s_name, "NUM") != NULL ||
+ (strstr(max_ec->s_name, "MAX") != NULL ||
+ strstr(max_ec->s_name, "max") != NULL ||
+ strstr(max_ec->s_name, "NUM") != NULL ||
strstr(max_ec->s_name, "num") != NULL))
return;