Module Name:    src
Committed By:   rillig
Date:           Thu Mar 18 22:51:32 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_init.c
        src/usr.bin/xlint/lint1: init.c

Log Message:
lint: replace undefined behavior during initialization with assertion

This only affects code that is already rejected by the compiler.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.7 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.8
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.7	Thu Mar 18 20:20:55 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Thu Mar 18 22:51:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.7 2021/03/18 20:20:55 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.8 2021/03/18 22:51:32 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -126,4 +126,11 @@ struct point point_with_mixed_designator
 	.x = 3,
 };
 
+int array_with_designator[] = {
+	111,
+	// FIXME: assertion failure '== STRUCT'
+	// .member = 222,
+	333,
+};
+
 // See d_struct_init_nested.c for a more complicated example.

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.95 src/usr.bin/xlint/lint1/init.c:1.96
--- src/usr.bin/xlint/lint1/init.c:1.95	Thu Mar 18 22:08:05 2021
+++ src/usr.bin/xlint/lint1/init.c	Thu Mar 18 22:51:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.95 2021/03/18 22:08:05 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.96 2021/03/18 22:51:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.95 2021/03/18 22:08:05 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.96 2021/03/18 22:51:32 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -428,14 +428,13 @@ initstack_pop_item(void)
 
 	istk->i_remaining--;
 	lint_assert(istk->i_remaining >= 0);
-
-	debug_step("new stack with updated remaining:");
-	debug_initstack_element(istk);
+	debug_step("%d elements remaining", istk->i_remaining);
 
 	if (namedmem != NULL) {
 		debug_step("initializing named member '%s'", namedmem->n_name);
 
-		/* XXX: undefined behavior if this is reached with an array? */
+		lint_assert(istk->i_type->t_tspec == STRUCT ||
+		    istk->i_type->t_tspec == UNION);
 		for (m = istk->i_type->t_str->sou_first_member;
 		     m != NULL; m = m->s_next) {
 

Reply via email to