Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix initialization of array with f...



details:   https://anonhg.NetBSD.org/src/rev/63342a0b8f33
branches:  trunk
changeset: 1027724:63342a0b8f33
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Dec 17 10:33:23 2021 +0000

description:
lint: fix initialization of array with fewer braces

Seen in Postfix, cleanup_strerror.c.

diffstat:

 tests/usr.bin/xlint/lint1/init.c   |  12 ++++++++----
 tests/usr.bin/xlint/lint1/init.exp |   1 -
 usr.bin/xlint/lint1/init.c         |   8 ++++----
 3 files changed, 12 insertions(+), 9 deletions(-)

diffs (77 lines):

diff -r 7bccecc1d5ee -r 63342a0b8f33 tests/usr.bin/xlint/lint1/init.c
--- a/tests/usr.bin/xlint/lint1/init.c  Fri Dec 17 10:22:30 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init.c  Fri Dec 17 10:33:23 2021 +0000
@@ -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 @@
  *
  * 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 @@
 };
 
 
-/* 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] */
diff -r 7bccecc1d5ee -r 63342a0b8f33 tests/usr.bin/xlint/lint1/init.exp
--- a/tests/usr.bin/xlint/lint1/init.exp        Fri Dec 17 10:22:30 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init.exp        Fri Dec 17 10:33:23 2021 +0000
@@ -1,2 +1,1 @@
 init.c(16): error: empty array declaration: empty_array_with_initializer [190]
-init.c(52): error: empty array declaration: points [190]
diff -r 7bccecc1d5ee -r 63342a0b8f33 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Fri Dec 17 10:22:30 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Fri Dec 17 10:33:23 2021 +0000
@@ -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 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 @@
                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);



Home | Main Index | Thread Index | Old Index