Module Name: src
Committed By: rillig
Date: Sat Jun 19 15:23:57 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: cgram.y init.c lint1.h
Log Message:
lint: replace undefined behavior with assertion failure
Triggered by this malformed code:
struct{int;
To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.198 -r1.199 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/xlint/lint1/lint1.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.226 src/usr.bin/xlint/lint1/cgram.y:1.227
--- src/usr.bin/xlint/lint1/cgram.y:1.226 Mon May 3 05:24:44 2021
+++ src/usr.bin/xlint/lint1/cgram.y Sat Jun 19 15:23:57 2021
@@ -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 @@ member_declaration:
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($$);
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.198 src/usr.bin/xlint/lint1/init.c:1.199
--- src/usr.bin/xlint/lint1/init.c:1.198 Sun Apr 18 09:53:03 2021
+++ src/usr.bin/xlint/lint1/init.c Sat Jun 19 15:23:57 2021
@@ -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 @@ unconst_cast(const void *p)
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)
{
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.102 src/usr.bin/xlint/lint1/lint1.h:1.103
--- src/usr.bin/xlint/lint1/lint1.h:1.102 Tue Jun 15 20:46:45 2021
+++ src/usr.bin/xlint/lint1/lint1.h Sat Jun 19 15:23:57 2021
@@ -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 @@ value_bits(unsigned bitsize)
return ~(~(uint64_t)0 << bitsize);
}
+
+/* C99 6.7.8p7 */
+static inline bool
+is_struct_or_union(tspec_t t)
+{
+ return t == STRUCT || t == UNION;
+}