Module Name: src Committed By: rillig Date: Fri Mar 26 16:59:19 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_247.c msg_247.exp src/usr.bin/xlint/lint1: tree.c Log Message: lint: allow pointer cast to 'char *' and 'unsigned char *' This reduces the number of warnings in the regular NetBSD build by 5560. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_247.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_247.exp cvs rdiff -u -r1.248 -r1.249 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.6 src/tests/usr.bin/xlint/lint1/msg_247.c:1.7 --- src/tests/usr.bin/xlint/lint1/msg_247.c:1.6 Fri Mar 26 16:19:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_247.c Fri Mar 26 16:59:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_247.c,v 1.6 2021/03/26 16:19:43 rillig Exp $ */ +/* $NetBSD: msg_247.c,v 1.7 2021/03/26 16:59:19 rillig Exp $ */ # 3 "msg_247.c" // Test for message: pointer cast from '%s' to '%s' may be troublesome [247] @@ -45,7 +45,7 @@ example(struct Other *arg) char * cast_to_char_pointer(struct Other *arg) { - return (char *)arg; /* expect: 247 *//* FIXME */ + return (char *)arg; } /* @@ -55,7 +55,7 @@ cast_to_char_pointer(struct Other *arg) unsigned char * cast_to_unsigned_char_pointer(struct Other *arg) { - return (unsigned char *)arg; /* expect: 247 *//* FIXME */ + return (unsigned char *)arg; } /* Index: src/tests/usr.bin/xlint/lint1/msg_247.exp diff -u src/tests/usr.bin/xlint/lint1/msg_247.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_247.exp:1.5 --- src/tests/usr.bin/xlint/lint1/msg_247.exp:1.4 Fri Mar 26 16:19:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_247.exp Fri Mar 26 16:59:19 2021 @@ -1,4 +1,2 @@ msg_247.c(31): warning: pointer cast from 'pointer to struct Other' to 'pointer to struct <unnamed>' may be troublesome [247] -msg_247.c(48): warning: pointer cast from 'pointer to struct Other' to 'pointer to char' may be troublesome [247] -msg_247.c(58): warning: pointer cast from 'pointer to struct Other' to 'pointer to unsigned char' 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] Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.248 src/usr.bin/xlint/lint1/tree.c:1.249 --- src/usr.bin/xlint/lint1/tree.c:1.248 Fri Mar 26 16:53:19 2021 +++ src/usr.bin/xlint/lint1/tree.c Fri Mar 26 16:59:18 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.248 2021/03/26 16:53:19 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.249 2021/03/26 16:59:18 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.248 2021/03/26 16:53:19 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.249 2021/03/26 16:59:18 rillig Exp $"); #endif #include <float.h> @@ -2230,6 +2230,9 @@ should_warn_about_pointer_cast(const typ if (tp->t_subt->t_str != tn->tn_type->t_subt->t_str) return true; + if (nst == CHAR || nst == UCHAR) + return false; /* for the sake of traditional C code */ + /* * XXX: Why should it be ok to cast between arbitrary structs that * just happen to be of the same size?