Fri Jan 1 19:28:51 2021 UTC ()
lint: document that C99-style initialization is necessarily buggy


(rillig)
diff -r1.53 -r1.54 src/usr.bin/xlint/lint1/init.c

cvs diff -r1.53 -r1.54 src/usr.bin/xlint/lint1/init.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/init.c 2021/01/01 19:15:58 1.53
+++ src/usr.bin/xlint/lint1/init.c 2021/01/01 19:28:51 1.54
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init.c,v 1.53 2021/01/01 19:15:58 rillig Exp $ */ 1/* $NetBSD: init.c,v 1.54 2021/01/01 19:28:51 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,38 +27,51 @@ @@ -27,38 +27,51 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) && !defined(lint) 39#if defined(__RCSID) && !defined(lint)
40__RCSID("$NetBSD: init.c,v 1.53 2021/01/01 19:15:58 rillig Exp $"); 40__RCSID("$NetBSD: init.c,v 1.54 2021/01/01 19:28:51 rillig Exp $");
41#endif 41#endif
42 42
43#include <ctype.h> 43#include <ctype.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46 46
47#include "lint1.h" 47#include "lint1.h"
48 48
49 49
50/* 50/*
51 * Type of stack which is used for initialisation of aggregate types. 51 * Type of stack which is used for initialisation of aggregate types.
 52 *
 53 * XXX: Since C99, a stack is an inappropriate data structure for modelling
 54 * an initialization, since the designators don't have to be listed in a
 55 * particular order and can designate parts of sub-objects. The member names
 56 * of non-leaf structs may thus appear repeatedly, as demonstrated in
 57 * d_init_pop_member.c.
 58 *
 59 * XXX: During initialization, there may be members of the top-level struct
 60 * that are partially initialized. The simple i_remaining cannot model this
 61 * appropriately.
 62 *
 63 * See C99 6.7.8, which spans 6 pages full of tricky details and carefully
 64 * selected examples.
52 */ 65 */
53typedef struct istk { 66typedef struct istk {
54 type_t *i_type; /* type of initialisation */ 67 type_t *i_type; /* type of initialisation */
55 type_t *i_subt; /* type of next level */ 68 type_t *i_subt; /* type of next level */
56 u_int i_brace : 1; /* need } for pop */ 69 u_int i_brace : 1; /* need } for pop */
57 u_int i_nolimit : 1; /* incomplete array type */ 70 u_int i_nolimit : 1; /* incomplete array type */
58 u_int i_namedmem : 1; /* has c9x named members */ 71 u_int i_namedmem : 1; /* has c9x named members */
59 sym_t *i_mem; /* next structure member */ 72 sym_t *i_mem; /* next structure member */
60 int i_remaining; /* # of remaining elements */ 73 int i_remaining; /* # of remaining elements */
61 struct istk *i_next; /* previous level */ 74 struct istk *i_next; /* previous level */
62} istk_t; 75} istk_t;
63 76
64typedef struct namlist { 77typedef struct namlist {