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: always initialize return values of...



details:   https://anonhg.NetBSD.org/src/rev/31e67b4835cf
branches:  trunk
changeset: 959660:31e67b4835cf
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 21 11:23:33 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/init.c |  18 ++++++++----------
 usr.bin/xlint/lint1/tree.c |  20 ++++++++++----------
 2 files changed, 18 insertions(+), 20 deletions(-)

diffs (124 lines):

diff -r bceb1dc9b713 -r 31e67b4835cf usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sun Feb 21 10:28:32 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sun Feb 21 11:23:33 2021 +0000
@@ -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 @@
 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 @@
                return;
        }
 
-       sc = initsym->s_scl;
+       sclass = initsym->s_scl;
 
        /*
         * Do not test for automatic aggregate initialisation. If the
@@ -759,7 +757,7 @@
         * 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 @@
                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 {
diff -r bceb1dc9b713 -r 31e67b4835cf usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Feb 21 10:28:32 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Feb 21 11:23:33 2021 +0000
@@ -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 @@
                }
                *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 @@
                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;
 }
 
 /*



Home | Main Index | Thread Index | Old Index