1/*	$NetBSD: msg_367.c,v 1.2 2024/03/03 10:27:18 rillig Exp $	*/
2# 3 "msg_367.c"
3
4// Test for message: empty description in '%.*s' [367]
5
6/*
7 * Each bit or field or comparison value gets a description.  If such a
8 * description is empty, the generated output will contain empty angle
9 * brackets or multiple adjacent commas or commas adjacent to an angle
10 * bracket, such as '<,,,,>'.
11 */
12
13/* lint1-extra-flags: -X 351 */
14
15typedef typeof(sizeof(0)) size_t;
16typedef unsigned long long uint64_t;
17
18int snprintb(char*, size_t, const char*, uint64_t);
19
20void
21old_style(unsigned u32)
22{
23	char buf[64];
24
25	/* expect+10: warning: empty description in '\001' [367] */
26	/* expect+9: warning: empty description in '\002' [367] */
27	/* expect+8: warning: empty description in '\003' [367] */
28	/* expect+7: warning: empty description in '\004' [367] */
29	snprintb(buf, sizeof(buf),
30	    "\020"
31	    "\001"
32	    "\002"
33	    "\003"
34	    "\004",
35	    u32);
36
37	/* expect+10: warning: empty description in '\001' [367] */
38	/* expect+9: warning: empty description in '\002' [367] */
39	/* expect+8: warning: empty description in '\003' [367] */
40	/* expect+7: warning: empty description in '\004' [367] */
41	snprintb(buf, sizeof(buf),
42	    "\020"
43	    "\001" "" ""
44	    "\002" "" ""
45	    "\003" "" ""
46	    "\004" "" "",
47	    u32);
48
49	// Single-letter descriptions are not empty.
50	snprintb(buf, sizeof(buf),
51	    "\020"
52	    "\001a"
53	    "\002b"
54	    "\003c"
55	    "\004d",
56	    u32);
57}
58
59void
60new_style(uint64_t u64)
61{
62	char buf[64];
63
64	/* expect+4: warning: empty description in 'b\000\0' [367] */
65	snprintb(buf, sizeof(buf),
66	    "\177\020"
67	    "b\000\0",
68	    u64);
69
70	/* expect+4: warning: empty description in 'f\000\010\0' [367] */
71	snprintb(buf, sizeof(buf),
72	    "\177\020"
73	    "f\000\010\0",
74	    u64);
75
76	// No warning, as 'F' does not take a description.
77	// If there were a description, it would simply be skipped.
78	snprintb(buf, sizeof(buf),
79	    "\177\020"
80	    "F\000\010\0",
81	    u64);
82
83	/* expect+4: warning: empty description in '=\000\0' [367] */
84	snprintb(buf, sizeof(buf),
85	    "\177\020"
86	    "=\000\0",
87	    u64);
88
89	/* expect+4: warning: empty description in ':\000\0' [367] */
90	snprintb(buf, sizeof(buf),
91	    "\177\020"
92	    ":\000\0",
93	    u64);
94
95	/* expect+4: warning: empty description in '*\0' [367] */
96	snprintb(buf, sizeof(buf),
97	    "\177\020"
98	    "*\0",
99	    u64);
100
101	// Single-letter descriptions are not empty.
102	snprintb(buf, sizeof(buf),
103	    "\177\020"
104	    "b\000b\0"
105	    "f\001\001f\0"
106	    "F\002\002F\0"
107		"=\000z\0"
108		":\001o\0"
109		"*d\0",
110	    u64 >> 1);
111
112	/* expect+6: warning: empty description in 'b\001""""""\0' [367] */
113	/* expect+5: warning: empty description in 'b\003""""""\0' [367] */
114	snprintb(buf, sizeof(buf),
115	    "\177\020"
116	    "b\001" "" "" "\0"
117	    "b\003" "" "" "\0",
118	    u64);
119}
120