Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: demonstrate warning fo...
details: https://anonhg.NetBSD.org/src/rev/c1d812f786f5
branches: trunk
changeset: 368115:c1d812f786f5
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 24 20:32:12 2022 +0000
description:
tests/lint: demonstrate warning for cast between compatible structs
diffstat:
tests/usr.bin/xlint/lint1/msg_247.c | 39 ++++++++++++++++++++++++++++++++++--
1 files changed, 36 insertions(+), 3 deletions(-)
diffs (71 lines):
diff -r 523cb49ccbbd -r c1d812f786f5 tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 20:16:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c Fri Jun 24 20:32:12 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_247.c,v 1.22 2022/06/24 20:16:21 rillig Exp $ */
+/* $NetBSD: msg_247.c,v 1.23 2022/06/24 20:32:12 rillig Exp $ */
# 3 "msg_247.c"
// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -103,7 +103,7 @@
void *allocate(void);
struct counter *
-counter_new(void)
+counter_new_typesafe(void)
{
struct counter_impl *impl = allocate();
impl->public_part.count = 12345;
@@ -111,6 +111,16 @@
return &impl->public_part;
}
+struct counter *
+counter_new_cast(void)
+{
+ struct counter_impl *impl = allocate();
+ impl->public_part.count = 12345;
+ impl->saved_count = 12346;
+ /* expect+1: warning: pointer cast from 'pointer to struct counter_impl' to 'pointer to struct counter' may be troublesome [247] */
+ return (struct counter *)impl;
+}
+
void
counter_increment(struct counter *counter)
{
@@ -156,7 +166,7 @@
*/
return (struct lhash_st_OPENSSL_STRING *)OPENSSL_LH_new();
}
-# 160 "msg_247.c" 2
+# 170 "msg_247.c" 2
void sink(const void *);
@@ -272,3 +282,26 @@
return t6;
}
+
+
+// From jemalloc.
+
+typedef struct ctl_node_s {
+ _Bool named;
+} ctl_node_t;
+
+typedef struct ctl_named_node_s {
+ ctl_node_t node;
+ const char *name;
+} ctl_named_node_t;
+
+void *
+cast_between_initial_struct(void *ptr)
+{
+ /* expect+1: warning: pointer cast from 'pointer to struct ctl_named_node_s' to 'pointer to struct ctl_node_s' may be troublesome [247] */
+ void *t1 = (ctl_node_t *)(ctl_named_node_t *)ptr;
+
+ void *t2 = (ctl_named_node_t *)(ctl_node_t *)ptr;
+
+ return t2;
+}
Home |
Main Index |
Thread Index |
Old Index