summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2022-06-24 19:27:43 +0000
committerrillig <rillig@NetBSD.org>2022-06-24 19:27:43 +0000
commit26c2fc3bf300ec0c5ac3f55389aa010b754d3dfd (patch)
tree9eb3dccf327d55bc39f7262683345eba4bd269fe
parent5956e08b6cf35ff8f5c348af2f7b1003a26e861a (diff)
lint: allow pointer cast from char to struct/union
-rw-r--r--tests/usr.bin/xlint/lint1/msg_247.c10
-rw-r--r--usr.bin/xlint/lint1/tree.c10
2 files changed, 12 insertions, 8 deletions
diff --git a/tests/usr.bin/xlint/lint1/msg_247.c b/tests/usr.bin/xlint/lint1/msg_247.c
index bded4096986..1f40d778bda 100644
--- a/tests/usr.bin/xlint/lint1/msg_247.c
+++ b/tests/usr.bin/xlint/lint1/msg_247.c
@@ -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 @@ plain_char_to_unsigned_type(char *cp)
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 --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index c55674c447c..552aa6e7eec 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -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 @@ should_warn_about_pointer_cast(const type_t *nstp, tspec_t nst,
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);
}