Home | History | Annotate | Line # | Download | only in lint1
msg_135.c revision 1.9
      1  1.9  rillig /*	$NetBSD: msg_135.c,v 1.9 2021/07/15 21:22:19 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_135.c"
      3  1.1  rillig 
      4  1.4  rillig // Test for message: converting '%s' to '%s' may cause alignment problem [135]
      5  1.1  rillig 
      6  1.3  rillig /* lint1-extra-flags: -h */
      7  1.3  rillig 
      8  1.6  rillig void sink(const void *);
      9  1.6  rillig 
     10  1.3  rillig unsigned
     11  1.9  rillig read_uint(const unsigned short **pp)
     12  1.3  rillig {
     13  1.3  rillig 	unsigned val;
     14  1.3  rillig 
     15  1.9  rillig 	/* expect+1: warning: converting 'pointer to const unsigned short' to 'pointer to const unsigned int' may cause alignment problem [135] */
     16  1.9  rillig 	val = *(const unsigned *)(*pp);
     17  1.3  rillig 	pp += sizeof(unsigned);
     18  1.3  rillig 	return val;
     19  1.3  rillig }
     20  1.6  rillig 
     21  1.6  rillig struct incomplete;	/* expect: never defined */
     22  1.6  rillig 
     23  1.6  rillig struct complete {
     24  1.6  rillig     int member;
     25  1.6  rillig };
     26  1.6  rillig 
     27  1.6  rillig /*
     28  1.6  rillig  * These types of conversions are typically seen in OpenSSL, when converting
     29  1.6  rillig  * from the publicly visible, incomplete 'struct lhash_st' to a private
     30  1.6  rillig  * implementation type such as 'struct lhash_st_OPENSSL_STRING'.
     31  1.6  rillig  *
     32  1.7  rillig  * Before tree.c 1.277 from 2021-04-17, lint warned about this, even though
     33  1.7  rillig  * there was not enough evidence that there really was an alignment problem,
     34  1.7  rillig  * resulting in many false positives.
     35  1.7  rillig  *
     36  1.6  rillig  * See openssl/lhash.h.
     37  1.6  rillig  */
     38  1.6  rillig void
     39  1.6  rillig pointer_to_structs(struct incomplete *incomplete)
     40  1.6  rillig {
     41  1.6  rillig 	struct complete *complete;
     42  1.6  rillig 
     43  1.7  rillig 	complete = (struct complete *)incomplete;
     44  1.6  rillig 	sink(complete);
     45  1.6  rillig }
     46  1.8  rillig 
     47  1.9  rillig /*
     48  1.9  rillig  * Before tree.c 1.316 from 2021-07-15, lint warned about pointer casts from
     49  1.9  rillig  * unsigned char or plain char to another type.  These casts often occur in
     50  1.9  rillig  * traditional code that does not use void pointers, even 30 years after C90
     51  1.9  rillig  * introduced 'void'.
     52  1.9  rillig  */
     53  1.8  rillig void
     54  1.8  rillig unsigned_char_to_unsigned_type(unsigned char *ucp)
     55  1.8  rillig {
     56  1.8  rillig 	unsigned short *usp;
     57  1.8  rillig 
     58  1.8  rillig 	usp = (unsigned short *)ucp;
     59  1.8  rillig 	sink(usp);
     60  1.8  rillig }
     61  1.8  rillig 
     62  1.9  rillig /*
     63  1.9  rillig  * Before tree.c 1.316 from 2021-07-15, lint warned about pointer casts from
     64  1.9  rillig  * unsigned char or plain char to another type.  These casts often occur in
     65  1.9  rillig  * traditional code that does not use void pointers, even 30 years after C90
     66  1.9  rillig  * introduced 'void'.
     67  1.9  rillig  */
     68  1.8  rillig void
     69  1.8  rillig plain_char_to_unsigned_type(char *cp)
     70  1.8  rillig {
     71  1.8  rillig 	unsigned short *usp;
     72  1.8  rillig 
     73  1.8  rillig 	usp = (unsigned short *)cp;
     74  1.8  rillig 	sink(usp);
     75  1.8  rillig }
     76