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 during ...



details:   https://anonhg.NetBSD.org/src/rev/8a140480c7f4
branches:  trunk
changeset: 981642:8a140480c7f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Mar 18 22:51:32 2021 +0000

description:
lint: replace undefined behavior during initialization with assertion

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

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_init.c |   9 ++++++++-
 usr.bin/xlint/lint1/init.c             |  11 +++++------
 2 files changed, 13 insertions(+), 7 deletions(-)

diffs (57 lines):

diff -r 47d2027195b8 -r 8a140480c7f4 tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c    Thu Mar 18 22:08:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c    Thu Mar 18 22:51:32 2021 +0000
@@ -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 @@
        .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.
diff -r 47d2027195b8 -r 8a140480c7f4 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Thu Mar 18 22:08:05 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Thu Mar 18 22:51:32 2021 +0000
@@ -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 @@
 
        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) {
 



Home | Main Index | Thread Index | Old Index