xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_375.c (revision 465ab238788e2dd3555edb0497148fa4c5f47dc7)
1 /*	$NetBSD: msg_375.c,v 1.4 2024/08/31 06:57:31 rillig Exp $	*/
2 # 3 "msg_375.c"
3 
4 // Test for message: comparison value '%.*s' (%ju) exceeds maximum field value %ju [375]
5 
6 /*
7  * When a bit field can take the values 0 to 15, there is no point comparing
8  * it to 16.
9  */
10 
11 /* lint1-extra-flags: -X 351 */
12 
13 typedef typeof(sizeof(0)) size_t;
14 typedef unsigned long long uint64_t;
15 
16 int snprintb(char *, size_t, const char *, uint64_t);
17 
18 void
19 example(uint64_t u64)
20 {
21 	char buf[64];
22 
23 	/* expect+14: warning: comparison value '\020' (16) exceeds maximum field value 15 [375] */
24 	/* expect+13: warning: comparison value '\377' (255) exceeds maximum field value 15 [375] */
25 	/* expect+12: warning: comparison value '\020' (16) exceeds maximum field value 15 [375] */
26 	/* expect+11: warning: comparison value '\377' (255) exceeds maximum field value 15 [375] */
27 	snprintb(buf, sizeof(buf),
28 	    "\177\020"
29 	    "f\000\004low\0"
30 		"=\01715\0"
31 		"=\02016\0"
32 		"=\37716\0"
33 	    "F\004\004low\0"
34 		":\01715\0"
35 		":\02016\0"
36 		":\37716\0",
37 	    u64);
38 }
39