xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_135.c (revision 53d1339bf7f9c7367b35a9e1ebe693f9b047a47b)
1 /*	$NetBSD: msg_135.c,v 1.7 2021/04/17 16:58:04 rillig Exp $	*/
2 # 3 "msg_135.c"
3 
4 // Test for message: converting '%s' to '%s' may cause alignment problem [135]
5 
6 /* lint1-extra-flags: -h */
7 
8 void sink(const void *);
9 
10 unsigned
11 read_uint(const unsigned char **pp)
12 {
13 	unsigned val;
14 
15 	val = *(const unsigned *)(*pp);	/* expect: 135 */
16 	pp += sizeof(unsigned);
17 	return val;
18 }
19 
20 struct incomplete;	/* expect: never defined */
21 
22 struct complete {
23     int member;
24 };
25 
26 /*
27  * These types of conversions are typically seen in OpenSSL, when converting
28  * from the publicly visible, incomplete 'struct lhash_st' to a private
29  * implementation type such as 'struct lhash_st_OPENSSL_STRING'.
30  *
31  * Before tree.c 1.277 from 2021-04-17, lint warned about this, even though
32  * there was not enough evidence that there really was an alignment problem,
33  * resulting in many false positives.
34  *
35  * See openssl/lhash.h.
36  */
37 void
38 pointer_to_structs(struct incomplete *incomplete)
39 {
40 	struct complete *complete;
41 
42 	complete = (struct complete *)incomplete;
43 	sink(complete);
44 }
45