Module Name: src
Committed By: rillig
Date: Fri Jun 24 19:20:39 UTC 2022
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_247.c
Log Message:
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'.
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/usr.bin/xlint/lint1/msg_247.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/msg_247.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247.c:1.18 src/tests/usr.bin/xlint/lint1/msg_247.c:1.19
--- src/tests/usr.bin/xlint/lint1/msg_247.c:1.18 Thu Jun 16 21:24:41 2022
+++ src/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 19:20:39 2022
@@ -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 @@ plain_char_to_unsigned_type(char *cp)
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);
+}