Module Name:    src
Committed By:   rillig
Date:           Thu Jul 15 21:12:46 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_135.c msg_135.exp msg_247.c
            msg_247.exp

Log Message:
tests/lint: demonstrate questionable warnings for pointer casts


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_135.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_135.exp
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/msg_247.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_247.exp

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_135.c
diff -u src/tests/usr.bin/xlint/lint1/msg_135.c:1.7 src/tests/usr.bin/xlint/lint1/msg_135.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_135.c:1.7	Sat Apr 17 16:58:04 2021
+++ src/tests/usr.bin/xlint/lint1/msg_135.c	Thu Jul 15 21:12:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_135.c,v 1.7 2021/04/17 16:58:04 rillig Exp $	*/
+/*	$NetBSD: msg_135.c,v 1.8 2021/07/15 21:12:46 rillig Exp $	*/
 # 3 "msg_135.c"
 
 // Test for message: converting '%s' to '%s' may cause alignment problem [135]
@@ -42,3 +42,25 @@ pointer_to_structs(struct incomplete *in
 	complete = (struct complete *)incomplete;
 	sink(complete);
 }
+
+void
+unsigned_char_to_unsigned_type(unsigned char *ucp)
+{
+	unsigned short *usp;
+
+	/* FIXME */
+	/* expect+1: warning: converting 'pointer to unsigned char' to 'pointer to unsigned short' may cause alignment problem [135] */
+	usp = (unsigned short *)ucp;
+	sink(usp);
+}
+
+void
+plain_char_to_unsigned_type(char *cp)
+{
+	unsigned short *usp;
+
+	/* FIXME */
+	/* expect+1: warning: converting 'pointer to char' to 'pointer to unsigned short' may cause alignment problem [135] */
+	usp = (unsigned short *)cp;
+	sink(usp);
+}

Index: src/tests/usr.bin/xlint/lint1/msg_135.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_135.exp:1.5 src/tests/usr.bin/xlint/lint1/msg_135.exp:1.6
--- src/tests/usr.bin/xlint/lint1/msg_135.exp:1.5	Sat Apr 17 16:58:04 2021
+++ src/tests/usr.bin/xlint/lint1/msg_135.exp	Thu Jul 15 21:12:46 2021
@@ -1,2 +1,4 @@
 msg_135.c(15): warning: converting 'pointer to const unsigned char' to 'pointer to const unsigned int' may cause alignment problem [135]
+msg_135.c(53): warning: converting 'pointer to unsigned char' to 'pointer to unsigned short' may cause alignment problem [135]
+msg_135.c(64): warning: converting 'pointer to char' to 'pointer to unsigned short' may cause alignment problem [135]
 msg_135.c(20): warning: struct incomplete never defined [233]

Index: src/tests/usr.bin/xlint/lint1/msg_247.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247.c:1.14 src/tests/usr.bin/xlint/lint1/msg_247.c:1.15
--- src/tests/usr.bin/xlint/lint1/msg_247.c:1.14	Sat Jul 10 17:35:54 2021
+++ src/tests/usr.bin/xlint/lint1/msg_247.c	Thu Jul 15 21:12:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_247.c,v 1.14 2021/07/10 17:35:54 rillig Exp $	*/
+/*	$NetBSD: msg_247.c,v 1.15 2021/07/15 21:12:46 rillig Exp $	*/
 # 3 "msg_247.c"
 
 // Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -154,3 +154,27 @@ lh_OPENSSL_STRING_new(void)
 	return (struct lhash_st_OPENSSL_STRING *)OPENSSL_LH_new();
 }
 # 157 "msg_247.c" 2
+
+void sink(const void *);
+
+void
+unsigned_char_to_unsigned_type(unsigned char *ucp)
+{
+	unsigned short *usp;
+
+	/* FIXME */
+	/* expect+1: warning: pointer cast from 'pointer to unsigned char' to 'pointer to unsigned short' may be troublesome [247] */
+	usp = (unsigned short *)ucp;
+	sink(usp);
+}
+
+void
+plain_char_to_unsigned_type(char *cp)
+{
+	unsigned short *usp;
+
+	/* FIXME */
+	/* expect+1: warning: pointer cast from 'pointer to char' to 'pointer to unsigned short' may be troublesome [247] */
+	usp = (unsigned short *)cp;
+	sink(usp);
+}

Index: src/tests/usr.bin/xlint/lint1/msg_247.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_247.exp:1.10 src/tests/usr.bin/xlint/lint1/msg_247.exp:1.11
--- src/tests/usr.bin/xlint/lint1/msg_247.exp:1.10	Fri Apr  9 20:00:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_247.exp	Thu Jul 15 21:12:46 2021
@@ -1,3 +1,5 @@
 msg_247.c(31): warning: pointer cast from 'pointer to struct Other' to 'pointer to struct <unnamed>' may be troublesome [247]
 msg_247.c(70): warning: pointer cast from 'pointer to struct Other' to 'pointer to signed char' may be troublesome [247]
+msg_247.c(167): warning: pointer cast from 'pointer to unsigned char' to 'pointer to unsigned short' may be troublesome [247]
+msg_247.c(178): warning: pointer cast from 'pointer to char' to 'pointer to unsigned short' may be troublesome [247]
 msg_247.c(134): warning: struct lhash_st never defined [233]

Reply via email to