Module Name:    src
Committed By:   rillig
Date:           Fri Dec 17 10:33:24 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: init.c init.exp
        src/usr.bin/xlint/lint1: init.c

Log Message:
lint: fix initialization of array with fewer braces

Seen in Postfix, cleanup_strerror.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/init.c \
    src/tests/usr.bin/xlint/lint1/init.exp
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/init.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/init.c
diff -u src/tests/usr.bin/xlint/lint1/init.c:1.4 src/tests/usr.bin/xlint/lint1/init.c:1.5
--- src/tests/usr.bin/xlint/lint1/init.c:1.4	Fri Dec 17 10:22:30 2021
+++ src/tests/usr.bin/xlint/lint1/init.c	Fri Dec 17 10:33:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.4 2021/12/17 10:22:30 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.5 2021/12/17 10:33:23 rillig Exp $	*/
 # 3 "init.c"
 
 /*
@@ -35,7 +35,7 @@ typedef struct {
  *
  * Seen in external/ibm-public/postfix/dist/src/util/dict.c(624).
  *
- * TODO: Properly handle this situation; as of init.c 1.212 from 2021-12-17,
+ * TODO: Properly handle this situation; as of init.c 1.214 from 2021-12-17,
  *  the below initialization sets in->in_err but shouldn't.
  */
 const histogram_entry hgr[] = {
@@ -44,10 +44,14 @@ const histogram_entry hgr[] = {
 };
 
 
-/* Initialization with fewer braces than usual, must still be accepted. */
+/*
+ * Initialization with fewer braces than usual, must still be accepted.
+ *
+ * TODO: Properly handle this situation; as of init.c 1.214 from 2021-12-17,
+ *  the below initialization sets in->in_err but shouldn't.
+ */
 struct {
 	int x, y;
 } points[] = {
 	0, 0, 3, 0, 0, 4, 3, 4
 };
-/* expect-1: error: empty array declaration: points [190] */
Index: src/tests/usr.bin/xlint/lint1/init.exp
diff -u src/tests/usr.bin/xlint/lint1/init.exp:1.4 src/tests/usr.bin/xlint/lint1/init.exp:1.5
--- src/tests/usr.bin/xlint/lint1/init.exp:1.4	Fri Dec 17 10:22:30 2021
+++ src/tests/usr.bin/xlint/lint1/init.exp	Fri Dec 17 10:33:23 2021
@@ -1,2 +1 @@
 init.c(16): error: empty array declaration: empty_array_with_initializer [190]
-init.c(52): error: empty array declaration: points [190]

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.213 src/usr.bin/xlint/lint1/init.c:1.214
--- src/usr.bin/xlint/lint1/init.c:1.213	Fri Dec 17 09:12:45 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Dec 17 10:33:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.213 2021/12/17 09:12:45 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.214 2021/12/17 10:33:23 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.213 2021/12/17 09:12:45 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.214 2021/12/17 10:33:23 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -161,7 +161,7 @@ struct initialization {
 	struct brace_level *in_brace_level;
 
 	/*
-	 * Is set as soon as a fatal error occurred in the initialization.
+	 * Is set when a structural error occurred in the initialization.
 	 * The effect is that the rest of the initialization is ignored
 	 * (parsed by yacc, expression trees built, but no initialization
 	 * takes place).
@@ -773,7 +773,7 @@ initialization_set_size_of_unknown_array
 		return;
 
 	dim = in->in_brace_level->bl_max_subscript;
-	if (dim == 0 && in->in_err)
+	if (dim == 0 && (in->in_err || in->in_brace_level->bl_confused))
 		dim = 1;	/* prevent "empty array declaration: %s" */
 
 	update_type_of_array_of_unknown_size(in->in_sym, dim);

Reply via email to