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: use 'unsigned int' for bit-size of types



details:   https://anonhg.NetBSD.org/src/rev/ff334ffcf0f9
branches:  trunk
changeset: 1023163:ff334ffcf0f9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 28 12:59:25 2021 +0000

description:
lint: use 'unsigned int' for bit-size of types

Lint does not need to support any types larger than 256 MB since they
don't occur in practice.  Practically, such large types have never been
supported at all since the function type_size_in_bits used int for the
internal calculations, resulting in overflows.

diffstat:

 usr.bin/xlint/common/lint.h    |   8 ++++----
 usr.bin/xlint/lint1/decl.c     |  10 +++++-----
 usr.bin/xlint/lint1/externs1.h |   4 ++--
 usr.bin/xlint/lint1/mem1.c     |   9 +++------
 usr.bin/xlint/lint1/tree.c     |  14 +++++++-------
 usr.bin/xlint/lint2/mem2.c     |   9 +++------
 6 files changed, 24 insertions(+), 30 deletions(-)

diffs (203 lines):

diff -r 61e4d68f7841 -r ff334ffcf0f9 usr.bin/xlint/common/lint.h
--- a/usr.bin/xlint/common/lint.h       Sat Aug 28 12:41:03 2021 +0000
+++ b/usr.bin/xlint/common/lint.h       Sat Aug 28 12:59:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lint.h,v 1.29 2021/08/22 15:06:49 rillig Exp $ */
+/*     $NetBSD: lint.h,v 1.30 2021/08/28 12:59:25 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -92,9 +92,9 @@
  * size of types, name and classification
  */
 typedef        struct {
-       size_t  tt_size_in_bits;
-       size_t  tt_portable_size_in_bits; /* different from tt_size_in_bits
-                                        * if pflag is set */
+       unsigned int tt_size_in_bits;
+       unsigned int tt_portable_size_in_bits; /* different from
+                                        * tt_size_in_bits if pflag is set */
        tspec_t tt_signed_counterpart;
        tspec_t tt_unsigned_counterpart;
        bool    tt_is_integer : 1;      /* integer type */
diff -r 61e4d68f7841 -r ff334ffcf0f9 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Aug 28 12:41:03 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Aug 28 12:59:25 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.225 2021/08/28 12:41:03 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.226 2021/08/28 12:59:25 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.225 2021/08/28 12:41:03 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.226 2021/08/28 12:59:25 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -581,7 +581,7 @@
                                if (mem == NULL)
                                        break;
                        }
-                       size_t x = (size_t)type_size_in_bits(mem->s_type);
+                       unsigned int x = type_size_in_bits(mem->s_type);
                        if (tp->t_tspec == STRUCT)
                                sp->sou_size_in_bits += x;
                        else if (x > sp->sou_size_in_bits)
@@ -1227,7 +1227,7 @@
        if (dsym->s_bitfield) {
                align(alignment_in_bits(tp), tp->t_flen);
                dsym->s_value.v_quad =
-                   (dcs->d_offset / size_in_bits(t)) * size_in_bits(t);
+                   dcs->d_offset - dcs->d_offset % size_in_bits(t);
                tp->t_foffs = dcs->d_offset - (int)dsym->s_value.v_quad;
                dcs->d_offset += tp->t_flen;
        } else {
@@ -1852,7 +1852,7 @@
                                        break;
                        }
                        sp->sou_size_in_bits +=
-                           (u_int)type_size_in_bits(mem->s_type);
+                           type_size_in_bits(mem->s_type);
                }
                if (mem->s_name != unnamed)
                        n++;
diff -r 61e4d68f7841 -r ff334ffcf0f9 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Aug 28 12:41:03 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Aug 28 12:59:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.133 2021/08/28 12:41:03 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.134 2021/08/28 12:59:25 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -262,7 +262,7 @@
                    bool, bool, bool);
 extern bool    constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
 extern strg_t  *cat_strings(strg_t *, strg_t *);
-extern  int64_t type_size_in_bits(const type_t *);
+extern  unsigned int type_size_in_bits(const type_t *);
 
 /*
  * func.c
diff -r 61e4d68f7841 -r ff334ffcf0f9 usr.bin/xlint/lint1/mem1.c
--- a/usr.bin/xlint/lint1/mem1.c        Sat Aug 28 12:41:03 2021 +0000
+++ b/usr.bin/xlint/lint1/mem1.c        Sat Aug 28 12:59:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mem1.c,v 1.49 2021/08/10 17:57:16 rillig Exp $ */
+/*     $NetBSD: mem1.c,v 1.50 2021/08/28 12:59:25 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem1.c,v 1.49 2021/08/10 17:57:16 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.50 2021/08/28 12:59:25 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -285,11 +285,8 @@
 void
 initmem(void)
 {
-       int     pgsz;
 
-       pgsz = getpagesize();
-       mblklen = ((MBLKSIZ + pgsz - 1) / pgsz) * pgsz;
-
+       mblklen = MBLKSIZ - MBLKSIZ % (unsigned int)getpagesize();
        mblks = xcalloc(nmblks = ML_INC, sizeof(*mblks));
 }
 
diff -r 61e4d68f7841 -r ff334ffcf0f9 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Aug 28 12:41:03 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Aug 28 12:59:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.354 2021/08/28 12:29:40 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.355 2021/08/28 12:59:25 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.354 2021/08/28 12:29:40 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.355 2021/08/28 12:59:25 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3296,7 +3296,7 @@
 tnode_t *
 build_sizeof(const type_t *tp)
 {
-       int64_t size_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
+       unsigned int size_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
        tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, size_in_bytes);
        tn->tn_system_dependent = true;
        return tn;
@@ -3314,16 +3314,16 @@
                error(111, "offsetof");
 
        // XXX: wrong size, no checking for sym fixme
-       int64_t offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
+       unsigned int offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
        tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes);
        tn->tn_system_dependent = true;
        return tn;
 }
 
-int64_t
+unsigned int
 type_size_in_bits(const type_t *tp)
 {
-       int     elem, elsz;
+       unsigned int elem, elsz;
        bool    flex;
 
        elem = 1;
@@ -3378,7 +3378,7 @@
                break;
        }
 
-       return (int64_t)elem * elsz;
+       return elem * elsz;
 }
 
 tnode_t *
diff -r 61e4d68f7841 -r ff334ffcf0f9 usr.bin/xlint/lint2/mem2.c
--- a/usr.bin/xlint/lint2/mem2.c        Sat Aug 28 12:41:03 2021 +0000
+++ b/usr.bin/xlint/lint2/mem2.c        Sat Aug 28 12:59:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mem2.c,v 1.12 2021/08/01 17:59:47 rillig Exp $ */
+/*     $NetBSD: mem2.c,v 1.13 2021/08/28 12:59:25 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem2.c,v 1.12 2021/08/01 17:59:47 rillig Exp $");
+__RCSID("$NetBSD: mem2.c,v 1.13 2021/08/28 12:59:25 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -59,11 +59,8 @@
 void
 initmem(void)
 {
-       int     pgsz;
 
-       pgsz = getpagesize();
-       mblklen = ((MBLKSIZ + pgsz - 1) / pgsz) * pgsz;
-
+       mblklen = MBLKSIZ - MBLKSIZ % (unsigned int)getpagesize();
        nxtfree = mblklen;
 }
 



Home | Main Index | Thread Index | Old Index