Module Name:    src
Committed By:   rillig
Date:           Fri Jun 24 19:27:43 UTC 2022

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

Log Message:
lint: allow pointer cast from char to struct/union


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/usr.bin/xlint/lint1/msg_247.c
cvs rdiff -u -r1.459 -r1.460 src/usr.bin/xlint/lint1/tree.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.19 src/tests/usr.bin/xlint/lint1/msg_247.c:1.20
--- src/tests/usr.bin/xlint/lint1/msg_247.c:1.19	Fri Jun 24 19:20:39 2022
+++ src/tests/usr.bin/xlint/lint1/msg_247.c	Fri Jun 24 19:27:43 2022
@@ -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] */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.459 src/usr.bin/xlint/lint1/tree.c:1.460
--- src/usr.bin/xlint/lint1/tree.c:1.459	Wed Jun 22 19:23:18 2022
+++ src/usr.bin/xlint/lint1/tree.c	Fri Jun 24 19:27:43 2022
@@ -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 typ
 	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);
 }
 

Reply via email to