Module Name:    src
Committed By:   rillig
Date:           Sat Jan 30 21:49:08 UTC 2021

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

Log Message:
lint: add type information to warning about troublesome casts

The previous warning text did not mention the actual types that are
involved in the type conversion.  These types can be hard to see from
the source code as soon as macros are involved, and even in plain code,
one would have to follow the declarations, which is an unnecessary
burden.  Lint already has all information about the involved types, so
there is no reason for omitting this crucial information.

Seen in external/mit/lua/dist/src/lvm.c and several other files.
Including the type information in the message immediately makes the
message scarier.

Before: pointer casts may be troublesome
After:  pointer cast from 'pointer to struct TString' to 'pointer to
        union GCUnion' may be troublesome


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.194 -r1.195 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/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.70 src/usr.bin/xlint/lint1/err.c:1.71
--- src/usr.bin/xlint/lint1/err.c:1.70	Sat Jan 30 17:56:29 2021
+++ src/usr.bin/xlint/lint1/err.c	Sat Jan 30 21:49:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.70 2021/01/30 17:56:29 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.71 2021/01/30 21:49:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.70 2021/01/30 17:56:29 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.71 2021/01/30 21:49:08 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -306,7 +306,7 @@ const	char *msgs[] = {
 	"illegal structure pointer combination",		      /* 244 */
 	"illegal structure pointer combination, op %s",		      /* 245 */
 	"dubious conversion of enum to '%s'",			      /* 246 */
-	"pointer casts may be troublesome",			      /* 247 */
+	"pointer cast from '%s' to '%s' may be troublesome",	      /* 247 */
 	"floating-point constant out of range",			      /* 248 */
 	"syntax error '%s'",					      /* 249 */
 	"unknown character \\%o",				      /* 250 */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.194 src/usr.bin/xlint/lint1/tree.c:1.195
--- src/usr.bin/xlint/lint1/tree.c:1.194	Sat Jan 30 18:16:45 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sat Jan 30 21:49:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.194 2021/01/30 18:16:45 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.195 2021/01/30 21:49:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.194 2021/01/30 18:16:45 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.195 2021/01/30 21:49:08 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2253,8 +2253,8 @@ check_pointer_conversion(op_t op, tnode_
 	     tp->t_subt->t_str != tn->tn_type->t_subt->t_str) ||
 	    psize(nt) != psize(ot)) {
 		if (cflag) {
-			/* pointer casts may be troublesome */
-			warning(247);
+			/* pointer cast from '%s' to '%s' may be troublesome */
+			warning(247, type_name(tn->tn_type), type_name(tp));
 		}
 	}
 }

Reply via email to