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 crash after syntax error in ar...



details:   https://anonhg.NetBSD.org/src/rev/40f6df9b8fb1
branches:  trunk
changeset: 364660:40f6df9b8fb1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 03 10:05:22 2022 +0000

description:
lint: fix crash after syntax error in array declaration

diffstat:

 tests/usr.bin/xlint/lint1/decl.c   |  10 +++++++++-
 tests/usr.bin/xlint/lint1/decl.exp |   2 ++
 usr.bin/xlint/lint1/decl.c         |  29 +++++++++++++++++++++++++++--
 3 files changed, 38 insertions(+), 3 deletions(-)

diffs (89 lines):

diff -r b497b92400be -r 40f6df9b8fb1 tests/usr.bin/xlint/lint1/decl.c
--- a/tests/usr.bin/xlint/lint1/decl.c  Sun Apr 03 09:49:36 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.c  Sun Apr 03 10:05:22 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl.c,v 1.12 2021/07/25 22:03:42 rillig Exp $ */
+/*     $NetBSD: decl.c,v 1.13 2022/04/03 10:05:23 rillig Exp $ */
 # 3 "decl.c"
 
 /*
@@ -170,3 +170,11 @@
 cover_func_declarator(void)
 {
 }
+
+/*
+ * Before decl.c 1.268 from 2022-04-03, lint ran into an assertion failure for
+ * "elsz > 0" in 'length'.
+ */
+/* expect+2: error: syntax error 'goto' [249] */
+/* expect+1: warning: empty array declaration: void_array_error [190] */
+void void_array_error[] goto;
diff -r b497b92400be -r 40f6df9b8fb1 tests/usr.bin/xlint/lint1/decl.exp
--- a/tests/usr.bin/xlint/lint1/decl.exp        Sun Apr 03 09:49:36 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.exp        Sun Apr 03 10:05:22 2022 +0000
@@ -11,5 +11,7 @@
 decl.c(80): error: syntax error '"' [249]
 decl.c(163): error: syntax error 'int' [249]
 decl.c(166): error: syntax error 'int' [249]
+decl.c(180): error: syntax error 'goto' [249]
 decl.c(114): warning: static function unused unused [236]
 decl.c(170): warning: static function cover_func_declarator unused [236]
+decl.c(180): warning: empty array declaration: void_array_error [190]
diff -r b497b92400be -r 40f6df9b8fb1 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Apr 03 09:49:36 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Apr 03 10:05:22 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.267 2022/04/02 22:38:45 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.268 2022/04/03 10:05:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.267 2022/04/02 22:38:45 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.268 2022/04/03 10:05:22 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -873,6 +873,14 @@
                /* FALLTHROUGH */
        default:
                elsz = size_in_bits(tp->t_tspec);
+               /*
+                * Workaround until the type parser (see add_function,
+                * add_array, add_pointer) does not construct the invalid
+                * intermediate declaration 'void b[4]' for the legitimate
+                * declaration 'void *b[4]'.
+                */
+               if (sytxerr > 0 && elsz == 0)
+                       elsz = CHAR_SIZE;
                lint_assert(elsz > 0);
                break;
        }
@@ -1328,6 +1336,23 @@
        tp = block_derive_type(stp, ARRAY);
        tp->t_dim = len;
 
+#if 0
+       /*
+        * As of 2022-04-03, the implementation of the type parser (see
+        * add_function, add_array, add_pointer) is strange.  When it sees
+        * the type 'void *b[4]', it first creates 'void b[4]' and only later
+        * inserts the '*' in the middle of the type.  Once created, a type
+        * should not be modified anymore.
+        *
+        * Since the intermediate type would be an array of void, but the
+        * final type is valid, this check cannot be enabled yet.
+        */
+       if (stp->t_tspec == VOID) {
+               /* array of incomplete type */
+               error(301);
+               tp->t_subt = gettyp(CHAR);
+       }
+#endif
        if (len < 0) {
                /* negative array dimension (%d) */
                error(20, len);



Home | Main Index | Thread Index | Old Index