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: fix a few lint warnings about type...



details:   https://anonhg.NetBSD.org/src/rev/61e4d68f7841
branches:  trunk
changeset: 1023162:61e4d68f7841
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 28 12:41:03 2021 +0000

description:
lint: fix a few lint warnings about type conversions

A simple 'unsigned int' is more than enough for representing the size of
a bit-field, as well as the maximum alignment of any type.

No functional change.

diffstat:

 usr.bin/xlint/lint1/decl.c     |  18 ++++++++++--------
 usr.bin/xlint/lint1/externs1.h |   4 ++--
 usr.bin/xlint/lint1/lint1.h    |   4 ++--
 3 files changed, 14 insertions(+), 12 deletions(-)

diffs (109 lines):

diff -r 20e720740ef5 -r 61e4d68f7841 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Aug 28 12:29:40 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Aug 28 12:41:03 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.224 2021/08/28 12:21:53 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.225 2021/08/28 12:41:03 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.224 2021/08/28 12:21:53 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.225 2021/08/28 12:41:03 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -552,15 +552,15 @@
        }
 }
 
-static size_t
+static unsigned int
 bitfieldsize(sym_t **mem)
 {
-       size_t len = (*mem)->s_type->t_flen;
+       unsigned int len = (*mem)->s_type->t_flen;
        while (*mem != NULL && (*mem)->s_type->t_bitfield) {
                len += (*mem)->s_type->t_flen;
                *mem = (*mem)->s_next;
        }
-       return ((len + INT_SIZE - 1) / INT_SIZE) * INT_SIZE;
+       return len - len % INT_SIZE;
 }
 
 static void
@@ -951,7 +951,7 @@
        return elem * elsz;
 }
 
-int
+unsigned int
 alignment_in_bits(const type_t *tp)
 {
        size_t  a;
@@ -1807,6 +1807,7 @@
        case ENUM_TAG:  return "enum";
        default:        lint_assert(/*CONSTCOND*/false);
        }
+       /* NOTREACHED */
 }
 
 /*
@@ -1826,7 +1827,7 @@
        setcomplete(tp, true);
 
        t = tp->t_tspec;
-       align(dcs->d_sou_align_in_bits, 0);
+       align((u_int)dcs->d_sou_align_in_bits, 0);
        sp = tp->t_str;
        sp->sou_align_in_bits = dcs->d_sou_align_in_bits;
        sp->sou_first_member = fmem;
@@ -1850,7 +1851,8 @@
                                if (mem == NULL)
                                        break;
                        }
-                       sp->sou_size_in_bits += type_size_in_bits(mem->s_type);
+                       sp->sou_size_in_bits +=
+                           (u_int)type_size_in_bits(mem->s_type);
                }
                if (mem->s_name != unnamed)
                        n++;
diff -r 20e720740ef5 -r 61e4d68f7841 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Aug 28 12:29:40 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Aug 28 12:41:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.132 2021/08/23 06:26:37 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.133 2021/08/28 12:41:03 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -187,7 +187,7 @@
 extern void    begin_type(void);
 extern void    end_type(void);
 extern int     length(const type_t *, const char *);
-extern int     alignment_in_bits(const type_t *);
+extern unsigned int alignment_in_bits(const type_t *);
 extern sym_t   *lnklst(sym_t *, sym_t *);
 extern void    check_type(sym_t *);
 extern sym_t   *declarator_1_struct_union(sym_t *);
diff -r 20e720740ef5 -r 61e4d68f7841 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Aug 28 12:29:40 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Aug 28 12:41:03 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.126 2021/08/28 12:21:53 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.127 2021/08/28 12:41:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -575,7 +575,7 @@
 static inline bool
 msb(int64_t q, tspec_t t)
 {
-       return (q & bit(size_in_bits(t) - 1)) != 0;
+       return (q & bit((unsigned int)size_in_bits(t) - 1)) != 0;
 }
 
 static inline uint64_t



Home | Main Index | Thread Index | Old Index