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: work around lint bug in initializa...
details: https://anonhg.NetBSD.org/src/rev/1b17500cb498
branches: trunk
changeset: 1027722:1b17500cb498
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Dec 17 09:12:45 2021 +0000
description:
lint: work around lint bug in initialization with few braces
Needs a proper fix later, but for now, this workaround allows to run
lint on Postfix again.
diffstat:
tests/usr.bin/xlint/lint1/init.c | 6 ++++--
tests/usr.bin/xlint/lint1/init.exp | 1 -
usr.bin/xlint/lint1/init.c | 35 +++++++++++++++++++++++++----------
3 files changed, 29 insertions(+), 13 deletions(-)
diffs (117 lines):
diff -r df9a277adc5b -r 1b17500cb498 tests/usr.bin/xlint/lint1/init.c
--- a/tests/usr.bin/xlint/lint1/init.c Fri Dec 17 08:27:06 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init.c Fri Dec 17 09:12:45 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.2 2021/12/17 01:00:50 rillig Exp $ */
+/* $NetBSD: init.c,v 1.3 2021/12/17 09:12:46 rillig Exp $ */
# 3 "init.c"
/*
@@ -34,9 +34,11 @@
* human readers, it is usually clearer to include them.
*
* 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,
+ * the below initialization sets in->in_err but shouldn't.
*/
const histogram_entry hgr[] = {
- /* expect+1: error: cannot initialize 'struct typedef histogram_entry' from 'pointer to char' [185] */
"odd", 5,
"even", 5,
};
diff -r df9a277adc5b -r 1b17500cb498 tests/usr.bin/xlint/lint1/init.exp
--- a/tests/usr.bin/xlint/lint1/init.exp Fri Dec 17 08:27:06 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init.exp Fri Dec 17 09:12:45 2021 +0000
@@ -1,2 +1,1 @@
init.c(16): error: empty array declaration: empty_array_with_initializer [190]
-init.c(40): error: cannot initialize 'struct typedef histogram_entry' from 'pointer to char' [185]
diff -r df9a277adc5b -r 1b17500cb498 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Fri Dec 17 08:27:06 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Fri Dec 17 09:12:45 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.212 2021/12/17 01:24:00 rillig Exp $ */
+/* $NetBSD: init.c,v 1.213 2021/12/17 09:12:45 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.212 2021/12/17 01:24:00 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.213 2021/12/17 09:12:45 rillig Exp $");
#endif
#include <stdlib.h>
@@ -766,11 +766,17 @@
static void
initialization_set_size_of_unknown_array(struct initialization *in)
{
+ size_t dim;
- if (in->in_sym->s_type->t_incomplete_array &&
- in->in_brace_level->bl_enclosing == NULL)
- update_type_of_array_of_unknown_size(in->in_sym,
- in->in_brace_level->bl_max_subscript);
+ if (!(in->in_sym->s_type->t_incomplete_array &&
+ in->in_brace_level->bl_enclosing == NULL))
+ return;
+
+ dim = in->in_brace_level->bl_max_subscript;
+ if (dim == 0 && in->in_err)
+ dim = 1; /* prevent "empty array declaration: %s" */
+
+ update_type_of_array_of_unknown_size(in->in_sym, dim);
}
static void
@@ -778,12 +784,11 @@
{
struct brace_level *bl;
- if (in->in_err)
- return;
-
debug_enter();
initialization_set_size_of_unknown_array(in);
+ if (in->in_err)
+ goto done;
bl = in->in_brace_level;
in->in_brace_level = bl->bl_enclosing;
@@ -795,6 +800,7 @@
if (bl != NULL)
designation_reset(&bl->bl_designation);
+done:
initialization_debug(in);
debug_leave();
}
@@ -853,8 +859,15 @@
tp = initialization_sub_type(in, true);
strg = tn->tn_string;
- if (!is_character_array(tp, strg->st_tspec))
+ if (!is_character_array(tp, strg->st_tspec)) {
+ /* TODO: recursively try first member or [0] */
+ if (is_struct_or_union(tp->t_tspec) ||
+ (tp->t_tspec == ARRAY &&
+ is_struct_or_union(tp->t_subt->t_tspec)))
+ in->in_err = true;
return false;
+ }
+
if (bl != NULL && tp->t_tspec != ARRAY && bl->bl_subscript != 0)
return false;
@@ -901,6 +914,8 @@
goto done;
if (initialization_init_array_using_string(in, tn))
goto advance;
+ if (in->in_err)
+ goto done;
if (bl != NULL)
brace_level_apply_designation(bl);
Home |
Main Index |
Thread Index |
Old Index