Module Name: src Committed By: rillig Date: Sun Feb 21 11:23:33 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: init.c tree.c Log Message: lint: always initialize return values of constant_addr Before, the caller was responsible for initializing the return values from the function. This was an unexpected burden. Ensure that in each branch that returns true, both return values are properly set. Strangely, the only caller of that function, init_using_expr, uses neither of the return values. It just tests whether the expression is constant or not. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/tree.c 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/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.80 src/usr.bin/xlint/lint1/init.c:1.81 --- src/usr.bin/xlint/lint1/init.c:1.80 Sun Feb 21 10:03:35 2021 +++ src/usr.bin/xlint/lint1/init.c Sun Feb 21 11:23:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.80 2021/02/21 10:03:35 rillig Exp $ */ +/* $NetBSD: init.c,v 1.81 2021/02/21 11:23:33 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.80 2021/02/21 10:03:35 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.81 2021/02/21 11:23:33 rillig Exp $"); #endif #include <stdlib.h> @@ -729,12 +729,10 @@ init_rbrace(void) void init_using_expr(tnode_t *tn) { - ptrdiff_t offs; - sym_t *sym; tspec_t lt, rt; tnode_t *ln; struct mbl *tmem; - scl_t sc; + scl_t sclass; debug_enter(); debug_named_member(); @@ -746,7 +744,7 @@ init_using_expr(tnode_t *tn) return; } - sc = initsym->s_scl; + sclass = initsym->s_scl; /* * Do not test for automatic aggregate initialisation. If the @@ -759,7 +757,7 @@ init_using_expr(tnode_t *tn) * Local initialisation of non-array-types with only one expression * without braces is done by ASSIGN */ - if ((sc == AUTO || sc == REG) && + if ((sclass == AUTO || sclass == REG) && initsym->s_type->t_tspec != ARRAY && initstk->i_enclosing == NULL) { ln = new_name_node(initsym, 0); ln->tn_type = tduptyp(ln->tn_type); @@ -836,10 +834,10 @@ init_using_expr(tnode_t *tn) tn = convert(INIT, 0, initstk->i_type, tn); if (tn != NULL && tn->tn_op != CON) { - sym = NULL; - offs = 0; + sym_t *sym; + ptrdiff_t offs; if (!constant_addr(tn, &sym, &offs)) { - if (sc == AUTO || sc == REG) { + if (sclass == AUTO || sclass == REG) { /* non-constant initializer */ c99ism(177); } else { Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.214 src/usr.bin/xlint/lint1/tree.c:1.215 --- src/usr.bin/xlint/lint1/tree.c:1.214 Sun Feb 21 10:28:33 2021 +++ src/usr.bin/xlint/lint1/tree.c Sun Feb 21 11:23:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.214 2021/02/21 10:28:33 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.214 2021/02/21 10:28:33 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $"); #endif #include <float.h> @@ -4215,19 +4215,22 @@ constant_addr(tnode_t *tn, sym_t **symp, } *symp = sym; *offsp = offs1 + offs2; - break; + return true; case ADDR: if (tn->tn_left->tn_op == NAME) { *symp = tn->tn_left->tn_sym; *offsp = 0; - } else if (tn->tn_left->tn_op == STRING) { + return true; + } else { /* * If this would be the front end of a compiler we - * would return a label instead of 0. + * would return a label instead of 0, at least if + * 'tn->tn_left->tn_op == STRING'. */ + *symp = NULL; *offsp = 0; + return true; } - break; case CVT: t = tn->tn_type->t_tspec; ot = tn->tn_left->tn_type->t_tspec; @@ -4248,13 +4251,10 @@ constant_addr(tnode_t *tn, sym_t **symp, else if (psize(t) != psize(ot)) return -1; #endif - if (!constant_addr(tn->tn_left, symp, offsp)) - return false; - break; + return constant_addr(tn->tn_left, symp, offsp); default: return false; } - return true; } /*