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 assertion failure after malfor...



details:   https://anonhg.NetBSD.org/src/rev/5bade2f7c32b
branches:  trunk
changeset: 984039:5bade2f7c32b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 19 16:05:07 2021 +0000

description:
lint: fix assertion failure after malformed statement

Found using afl.

diffstat:

 tests/usr.bin/xlint/lint1/msg_249.c   |  15 ++++++++++++---
 tests/usr.bin/xlint/lint1/msg_249.exp |   2 +-
 usr.bin/xlint/lint1/func.c            |   8 +++++---
 3 files changed, 18 insertions(+), 7 deletions(-)

diffs (58 lines):

diff -r 31912720814e -r 5bade2f7c32b tests/usr.bin/xlint/lint1/msg_249.c
--- a/tests/usr.bin/xlint/lint1/msg_249.c       Sat Jun 19 15:51:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_249.c       Sat Jun 19 16:05:07 2021 +0000
@@ -1,7 +1,16 @@
-/*     $NetBSD: msg_249.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_249.c,v 1.3 2021/06/19 16:05:07 rillig Exp $       */
 # 3 "msg_249.c"
 
 // Test for message: syntax error '%s' [249]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/*
+ * Before func.c 1.110 from 2021-06-19, lint ran into this:
+ * assertion "cstmt->c_kind == kind" failed in end_control_statement
+ */
+void
+function(void)
+{
+       if (0)
+               ;
+       );                      /* expect: syntax error ')' */
+}
diff -r 31912720814e -r 5bade2f7c32b tests/usr.bin/xlint/lint1/msg_249.exp
--- a/tests/usr.bin/xlint/lint1/msg_249.exp     Sat Jun 19 15:51:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_249.exp     Sat Jun 19 16:05:07 2021 +0000
@@ -1,1 +1,1 @@
-msg_249.c(6): error: syntax error ':' [249]
+msg_249.c(15): error: syntax error ')' [249]
diff -r 31912720814e -r 5bade2f7c32b usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Jun 19 15:51:11 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Jun 19 16:05:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.109 2021/06/19 15:51:11 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.110 2021/06/19 16:05:07 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.109 2021/06/19 15:51:11 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.110 2021/06/19 16:05:07 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -173,7 +173,9 @@
        case_label_t *cl, *next;
 
        lint_assert(cstmt != NULL);
-       lint_assert(cstmt->c_kind == kind);
+
+       while (cstmt->c_kind != kind)
+               cstmt = cstmt->c_surrounding;
 
        ci = cstmt;
        cstmt = ci->c_surrounding;



Home | Main Index | Thread Index | Old Index