Module Name:    src
Committed By:   rillig
Date:           Sat Aug 28 12:41:03 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: decl.c externs1.h lint1.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.132 -r1.133 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/xlint/lint1/lint1.h

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/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.224 src/usr.bin/xlint/lint1/decl.c:1.225
--- src/usr.bin/xlint/lint1/decl.c:1.224	Sat Aug 28 12:21:53 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sat Aug 28 12:41:03 2021
@@ -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 @@ settdsym(type_t *tp, sym_t *sym)
 	}
 }
 
-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 @@ length(const type_t *tp, const char *nam
 	return elem * elsz;
 }
 
-int
+unsigned int
 alignment_in_bits(const type_t *tp)
 {
 	size_t	a;
@@ -1807,6 +1807,7 @@ storage_class_name(scl_t sc)
 	case ENUM_TAG:	return "enum";
 	default:	lint_assert(/*CONSTCOND*/false);
 	}
+	/* NOTREACHED */
 }
 
 /*
@@ -1826,7 +1827,7 @@ complete_tag_struct_or_union(type_t *tp,
 	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 @@ complete_tag_struct_or_union(type_t *tp,
 				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++;

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.132 src/usr.bin/xlint/lint1/externs1.h:1.133
--- src/usr.bin/xlint/lint1/externs1.h:1.132	Mon Aug 23 06:26:37 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Aug 28 12:41:03 2021
@@ -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	setasm(void);
 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 *);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.126 src/usr.bin/xlint/lint1/lint1.h:1.127
--- src/usr.bin/xlint/lint1/lint1.h:1.126	Sat Aug 28 12:21:53 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Aug 28 12:41:03 2021
@@ -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 @@ bit(unsigned i)
 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

Reply via email to