Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint lint: in malloc calls, use 'sizeof *ptr' inste...



details:   https://anonhg.NetBSD.org/src/rev/f5c067016624
branches:  trunk
changeset: 981922:f5c067016624
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 26 20:31:07 2021 +0000

description:
lint: in malloc calls, use 'sizeof *ptr' instead of 'sizeof(type)'

No functional change.

diffstat:

 usr.bin/xlint/common/tyname.c |   8 +++---
 usr.bin/xlint/lint1/cgram.y   |   8 +++---
 usr.bin/xlint/lint1/decl.c    |  32 ++++++++++++------------
 usr.bin/xlint/lint1/err.c     |   6 ++--
 usr.bin/xlint/lint1/func.c    |  10 +++---
 usr.bin/xlint/lint1/init.c    |  10 +++---
 usr.bin/xlint/lint1/lex.c     |  55 ++++++++++++++++++++++-------------------
 usr.bin/xlint/lint1/main1.c   |   6 ++--
 usr.bin/xlint/lint1/mem1.c    |  18 ++++++------
 usr.bin/xlint/lint1/tree.c    |  40 +++++++++++++++---------------
 usr.bin/xlint/lint2/chk.c     |   6 ++--
 usr.bin/xlint/lint2/emit2.c   |   6 ++--
 usr.bin/xlint/lint2/hash.c    |  12 ++++----
 usr.bin/xlint/lint2/main2.c   |   8 +++---
 usr.bin/xlint/lint2/read.c    |  56 +++++++++++++++++++++---------------------
 usr.bin/xlint/xlint/xlint.c   |  48 ++++++++++++++++++------------------
 16 files changed, 166 insertions(+), 163 deletions(-)

diffs (truncated from 1268 to 300 lines):

diff -r ba62ecfc5b16 -r f5c067016624 usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Fri Mar 26 19:17:58 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Fri Mar 26 20:31:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.34 2021/03/07 17:12:41 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.35 2021/03/26 20:31:07 rillig Exp $       */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.34 2021/03/07 17:12:41 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.35 2021/03/26 20:31:07 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -74,7 +74,7 @@
 {
        name_tree_node *n;
 
-       n = xmalloc(sizeof(*n));
+       n = xmalloc(sizeof *n);
        n->ntn_name = xstrdup(name);
        n->ntn_less = NULL;
        n->ntn_greater = NULL;
@@ -137,7 +137,7 @@
 static void
 buf_add_int(buffer *buf, int n)
 {
-       char num[1 + sizeof(n) * CHAR_BIT + 1];
+       char num[1 + sizeof n * CHAR_BIT + 1];
 
        snprintf(num, sizeof num, "%d", n);
        buf_add(buf, num);
diff -r ba62ecfc5b16 -r f5c067016624 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Mar 26 19:17:58 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Mar 26 20:31:07 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.203 2021/03/26 18:54:39 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.204 2021/03/26 20:31:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.203 2021/03/26 18:54:39 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.204 2021/03/26 20:31:07 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1197,7 +1197,7 @@
 
 asterisk:
          T_ASTERISK {
-               $$ = xcalloc(1, sizeof (pqinf_t));
+               $$ = xcalloc(1, sizeof *$$);
                $$->p_pcnt = 1;
          }
        ;
@@ -1213,7 +1213,7 @@
 
 type_qualifier:
          T_QUAL {
-               $$ = xcalloc(1, sizeof (pqinf_t));
+               $$ = xcalloc(1, sizeof *$$);
                if ($1 == CONST) {
                        $$->p_const = true;
                } else if ($1 == VOLATILE) {
diff -r ba62ecfc5b16 -r f5c067016624 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Mar 26 19:17:58 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Mar 26 20:31:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.160 2021/03/26 17:44:52 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.161 2021/03/26 20:31:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.160 2021/03/26 17:44:52 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.161 2021/03/26 20:31:07 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -91,7 +91,7 @@
        int i;
 
        /* declaration stack */
-       dcs = xcalloc(1, sizeof (dinfo_t));
+       dcs = xcalloc(1, sizeof *dcs);
        dcs->d_ctx = EXTERN;
        dcs->d_ldlsym = &dcs->d_dlsyms;
 
@@ -99,7 +99,7 @@
        inittyp();
 
        /* shared type structures */
-       typetab = xcalloc(NTSPEC, sizeof (type_t));
+       typetab = xcalloc(NTSPEC, sizeof *typetab);
        for (i = 0; i < NTSPEC; i++)
                typetab[i].t_tspec = NOTSPEC;
        typetab[BOOL].t_tspec = BOOL;
@@ -162,7 +162,7 @@
 {
        type_t  *ntp;
 
-       ntp = tgetblk(sizeof (type_t));
+       ntp = tgetblk(sizeof *ntp);
        *ntp = *tp;
        return ntp;
 }
@@ -593,7 +593,7 @@
        dinfo_t *di;
 
        /* put a new element on the declaration stack */
-       di = xcalloc(1, sizeof (dinfo_t));
+       di = xcalloc(1, sizeof *di);
        di->d_next = dcs;
        dcs = di;
        di->d_ctx = sc;
@@ -1262,7 +1262,7 @@
 {
 
        if (dsym == NULL) {
-               dsym = getblk(sizeof (sym_t));
+               dsym = getblk(sizeof *dsym);
                dsym->s_name = unnamed;
                dsym->s_kind = FMEMBER;
                dsym->s_scl = MOS;
@@ -1334,7 +1334,7 @@
                return decl;
 
        while (pi != NULL) {
-               *tpp = tp = getblk(sizeof (type_t));
+               *tpp = tp = getblk(sizeof *tp);
                tp->t_tspec = PTR;
                tp->t_const = pi->p_const;
                tp->t_volatile = pi->p_volatile;
@@ -1361,7 +1361,7 @@
        if (*tpp == NULL)
            return decl;
 
-       *tpp = tp = getblk(sizeof (type_t));
+       *tpp = tp = getblk(sizeof *tp);
        tp->t_tspec = ARRAY;
        tp->t_subt = dcs->d_type;
        tp->t_dim = n;
@@ -1416,7 +1416,7 @@
        if (*tpp == NULL)
            return decl;
 
-       *tpp = tp = getblk(sizeof (type_t));
+       *tpp = tp = getblk(sizeof *tp);
        tp->t_tspec = FUNC;
        tp->t_subt = dcs->d_next->d_type;
        if ((tp->t_proto = dcs->d_proto) != false)
@@ -1670,19 +1670,19 @@
                }
                if (tag->s_scl == NOSCL) {
                        tag->s_scl = scl;
-                       tag->s_type = tp = getblk(sizeof (type_t));
+                       tag->s_type = tp = getblk(sizeof *tp);
                        tp->t_packed = dcs->d_packed;
                } else {
                        tp = tag->s_type;
                }
        } else {
-               tag = getblk(sizeof (sym_t));
+               tag = getblk(sizeof *tag);
                tag->s_name = unnamed;
                UNIQUE_CURR_POS(tag->s_def_pos);
                tag->s_kind = FTAG;
                tag->s_scl = scl;
                tag->s_block_level = -1;
-               tag->s_type = tp = getblk(sizeof (type_t));
+               tag->s_type = tp = getblk(sizeof *tp);
                tp->t_packed = dcs->d_packed;
                dcs->d_next->d_nonempty_decl = true;
        }
@@ -1690,12 +1690,12 @@
        if (tp->t_tspec == NOTSPEC) {
                tp->t_tspec = kind;
                if (kind != ENUM) {
-                       tp->t_str = getblk(sizeof (struct_or_union));
+                       tp->t_str = getblk(sizeof *tp->t_str);
                        tp->t_str->sou_align_in_bits = CHAR_SIZE;
                        tp->t_str->sou_tag = tag;
                } else {
                        tp->t_is_enum = true;
-                       tp->t_enum = getblk(sizeof(*tp->t_enum));
+                       tp->t_enum = getblk(sizeof *tp->t_enum);
                        tp->t_enum->en_tag = tag;
                }
                setcomplete(tp, false);
@@ -2872,7 +2872,7 @@
 
        lint_assert(dcs->d_ctx == ABSTRACT || dcs->d_ctx == PROTO_ARG);
 
-       sym = getblk(sizeof (sym_t));
+       sym = getblk(sizeof *sym);
 
        sym->s_name = unnamed;
        sym->s_def = DEF;
diff -r ba62ecfc5b16 -r f5c067016624 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Fri Mar 26 19:17:58 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Fri Mar 26 20:31:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.92 2021/03/22 15:29:43 rillig Exp $  */
+/*     $NetBSD: err.c,v 1.93 2021/03/26 20:31:07 rillig Exp $  */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.92 2021/03/22 15:29:43 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.93 2021/03/26 20:31:07 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -405,7 +405,7 @@
 {
        size_t i;
 
-       for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
+       for (i = 0; i < sizeof msgs / sizeof msgs[0]; i++)
                printf("%zu\t%s\n", i, msgs[i]);
 }
 
diff -r ba62ecfc5b16 -r f5c067016624 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Fri Mar 26 19:17:58 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c        Fri Mar 26 20:31:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.97 2021/03/26 19:17:58 rillig Exp $ */
+/*     $NetBSD: func.c,v 1.98 2021/03/26 20:31:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.97 2021/03/26 19:17:58 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.98 2021/03/26 20:31:07 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -157,7 +157,7 @@
 {
        cstk_t  *ci;
 
-       ci = xcalloc(1, sizeof (cstk_t));
+       ci = xcalloc(1, sizeof *ci);
        ci->c_kind = kind;
        ci->c_surrounding = cstmt;
        cstmt = ci;
@@ -683,7 +683,7 @@
         * duplicated. This is not too complicated because it is
         * only an integer type.
         */
-       tp = xcalloc(1, sizeof (type_t));
+       tp = xcalloc(1, sizeof *tp);
        if (tn != NULL) {
                tp->t_tspec = tn->tn_type->t_tspec;
                if ((tp->t_is_enum = tn->tn_type->t_is_enum) != false)
@@ -1049,7 +1049,7 @@
        if (tn != NULL) {
 
                /* Create a temporary node for the left side */
-               ln = tgetblk(sizeof (tnode_t));
+               ln = tgetblk(sizeof *ln);
                ln->tn_op = NAME;
                ln->tn_type = tduptyp(funcsym->s_type->t_subt);
                ln->tn_type->t_const = false;
diff -r ba62ecfc5b16 -r f5c067016624 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Fri Mar 26 19:17:58 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Fri Mar 26 20:31:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.133 2021/03/25 22:53:05 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.134 2021/03/26 20:31:07 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.133 2021/03/25 22:53:05 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.134 2021/03/26 20:31:07 rillig Exp $");
 #endif
 
 #include <stdlib.h>



Home | Main Index | Thread Index | Old Index