Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: demonstrate dubious wa...
details: https://anonhg.NetBSD.org/src/rev/18bfcbcd382b
branches: trunk
changeset: 368111:18bfcbcd382b
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 24 19:20:39 2022 +0000
description:
tests/lint: demonstrate dubious warnings for pointer casts
Casting a 'pointer to char' to a 'pointer to anything else' is already
allowed, except for 'pointer to struct/union'. The cause for this
inconsistency is the wrong order of checks in
'should_warn_about_pointer_cast'.
diffstat:
tests/usr.bin/xlint/lint1/msg_247.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diffs (27 lines):
diff -r c77c364d7c9b -r 18bfcbcd382b tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 16:50:00 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 19:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_247.c,v 1.18 2022/06/16 21:24:41 rillig Exp $ */
+/* $NetBSD: msg_247.c,v 1.19 2022/06/24 19:20:39 rillig Exp $ */
# 3 "msg_247.c"
// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -189,3 +189,17 @@
usp = (unsigned short *)cp;
sink(usp);
}
+
+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] */
+ sink((struct counter *)(signed char *)ptr);
+}
Home |
Main Index |
Thread Index |
Old Index