Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add more tests for arr...
details: https://anonhg.NetBSD.org/src/rev/e1f4ba4dde59
branches: trunk
changeset: 373036:e1f4ba4dde59
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 14 11:15:07 2023 +0000
description:
tests/lint: add more tests for array/enum mismatch
diffstat:
tests/usr.bin/xlint/lint1/msg_348.c | 50 ++++++++++++++++++++++++++++++++++++-
1 files changed, 49 insertions(+), 1 deletions(-)
diffs (71 lines):
diff -r 8b9e5ab9ca6f -r e1f4ba4dde59 tests/usr.bin/xlint/lint1/msg_348.c
--- a/tests/usr.bin/xlint/lint1/msg_348.c Sat Jan 14 10:38:36 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_348.c Sat Jan 14 11:15:07 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_348.c,v 1.7 2023/01/08 15:22:33 rillig Exp $ */
+/* $NetBSD: msg_348.c,v 1.8 2023/01/14 11:15:07 rillig Exp $ */
# 3 "msg_348.c"
// Test for message 348: maximum value %d of '%s' does not match maximum array index %d [348]
@@ -8,6 +8,9 @@
enum color {
red,
green,
+ /* expect+5: previous declaration of 'blue' [260] */
+ /* expect+4: previous declaration of 'blue' [260] */
+ /* expect+3: previous declaration of 'blue' [260] */
/* expect+2: previous declaration of 'blue' [260] */
/* expect+1: previous declaration of 'blue' [260] */
blue
@@ -100,6 +103,51 @@
return (&name)[color];
}
+/*
+ * If the accessed array has character type, it may contain a trailing null
+ * character.
+ */
+void
+color_initial_letter(enum color color)
+{
+ static const char len_2_null[] = "RG";
+ static const char len_3_null[] = "RGB";
+ static const char len_4_null[] = "RGB_";
+
+ static const char len_2_of_3[3] = "RG";
+ static const char len_3_of_3[3] = "RGB";
+ static const char len_4_of_4[4] = "RGB_";
+
+ /* TODO: array is too short */
+ if (len_2_null[color] != '\0')
+ return;
+
+ /* FIXME: lint should not warn since the maximum usable array index is 2 */
+ /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] */
+ if (len_3_null[color] != '\0')
+ return;
+
+ /* FIXME: lint should not warn since the maximum usable array index is 3, not 4 */
+ /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 4 [348] */
+ if (len_4_null[color] != '\0')
+ return;
+
+ /*
+ * The array has 3 elements, as expected. If lint were to inspect
+ * the content of the array, it could see that [2] is a null
+ * character. That null character may be intended though.
+ */
+ if (len_2_of_3[color] != '\0')
+ return;
+
+ if (len_3_of_3[color] != '\0')
+ return;
+
+ /* expect+1: warning: maximum value 2 of 'enum color' does not match maximum array index 3 [348] */
+ if (len_4_of_4[color])
+ return;
+}
+
extern const char *incomplete_color_name[];
const char *
Home |
Main Index |
Thread Index |
Old Index