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: replace undefined behavior with as...



details:   https://anonhg.NetBSD.org/src/rev/656428063906
branches:  trunk
changeset: 984037:656428063906
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 19 15:23:57 2021 +0000

description:
lint: replace undefined behavior with assertion failure

Triggered by this malformed code:

        struct{int;

diffstat:

 usr.bin/xlint/lint1/cgram.y |   5 +++--
 usr.bin/xlint/lint1/init.c  |  12 ++----------
 usr.bin/xlint/lint1/lint1.h |   9 ++++++++-
 3 files changed, 13 insertions(+), 13 deletions(-)

diffs (80 lines):

diff -r b655aaa66672 -r 656428063906 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jun 19 14:28:04 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jun 19 15:23:57 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.226 2021/05/03 05:24:44 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.227 2021/06/19 15:23:57 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.226 2021/05/03 05:24:44 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.227 2021/06/19 15:23:57 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -843,6 +843,7 @@
                if (!Sflag)
                        /* anonymous struct/union members is a C9X feature */
                        warning(49);
+               lint_assert(is_struct_or_union(dcs->d_type->t_tspec));
                $$ = dcs->d_type->t_str->sou_first_member;
                /* add all the members of the anonymous struct/union */
                anonymize($$);
diff -r b655aaa66672 -r 656428063906 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sat Jun 19 14:28:04 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sat Jun 19 15:23:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.198 2021/04/18 09:53:03 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.199 2021/06/19 15:23:57 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.198 2021/04/18 09:53:03 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.199 2021/06/19 15:23:57 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -234,14 +234,6 @@
        return r;
 }
 
-/* C99 6.7.8p7 */
-static bool
-is_struct_or_union(tspec_t t)
-{
-
-       return t == STRUCT || t == UNION;
-}
-
 static bool
 has_automatic_storage_duration(const sym_t *sym)
 {
diff -r b655aaa66672 -r 656428063906 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Jun 19 14:28:04 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Jun 19 15:23:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.102 2021/06/15 20:46:45 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.103 2021/06/19 15:23:57 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -555,3 +555,10 @@
 
        return ~(~(uint64_t)0 << bitsize);
 }
+
+/* C99 6.7.8p7 */
+static inline bool
+is_struct_or_union(tspec_t t)
+{
+       return t == STRUCT || t == UNION;
+}



Home | Main Index | Thread Index | Old Index