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: allow pointer cast from char to st...
details: https://anonhg.NetBSD.org/src/rev/b5d9f8c7a789
branches: trunk
changeset: 368112:b5d9f8c7a789
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 24 19:27:43 2022 +0000
description:
lint: allow pointer cast from char to struct/union
diffstat:
tests/usr.bin/xlint/lint1/msg_247.c | 10 +++++++---
usr.bin/xlint/lint1/tree.c | 10 +++++-----
2 files changed, 12 insertions(+), 8 deletions(-)
diffs (66 lines):
diff -r 18bfcbcd382b -r b5d9f8c7a789 tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 19:20:39 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 19:27:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_247.c,v 1.19 2022/06/24 19:20:39 rillig Exp $ */
+/* $NetBSD: msg_247.c,v 1.20 2022/06/24 19:27:43 rillig Exp $ */
# 3 "msg_247.c"
// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -190,14 +190,18 @@
sink(usp);
}
+/*
+ * Before tree.c 1.460 from 2022-06-24, lint warned about pointer casts from
+ * unsigned char or plain char to a struct or union type. These casts often
+ * occur in traditional code that does not use void pointers, even 30 years
+ * after C90 introduced 'void'.
+ */
void
char_to_struct(void *ptr)
{
- /* expect+1: warning: pointer cast from 'pointer to char' to 'pointer to struct counter' may be troublesome [247] */
sink((struct counter *)(char *)ptr);
- /* expect+1: warning: pointer cast from 'pointer to unsigned char' to 'pointer to struct counter' may be troublesome [247] */
sink((struct counter *)(unsigned char *)ptr);
/* expect+1: warning: pointer cast from 'pointer to signed char' to 'pointer to struct counter' may be troublesome [247] */
diff -r 18bfcbcd382b -r b5d9f8c7a789 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Fri Jun 24 19:20:39 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c Fri Jun 24 19:27:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.459 2022/06/22 19:23:18 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.460 2022/06/24 19:27:43 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.459 2022/06/22 19:23:18 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.460 2022/06/24 19:27:43 rillig Exp $");
#endif
#include <float.h>
@@ -2507,14 +2507,14 @@
if (is_incomplete(nstp) || is_incomplete(ostp))
return false;
- if (is_struct_or_union(nst) && nstp->t_str != ostp->t_str)
- return true;
-
if (nst == CHAR || nst == UCHAR)
return false; /* for the sake of traditional C code */
if (ost == CHAR || ost == UCHAR)
return false; /* for the sake of traditional C code */
+ if (is_struct_or_union(nst) && nstp->t_str != ostp->t_str)
+ return true;
+
return portable_size_in_bits(nst) != portable_size_in_bits(ost);
}
Home |
Main Index |
Thread Index |
Old Index