xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_363.c (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1 /*	$NetBSD: msg_363.c,v 1.6 2024/08/31 06:57:31 rillig Exp $	*/
2 # 3 "msg_363.c"
3 
4 // Test for message: escaped character '%.*s' in description of conversion '%.*s' [363]
5 
6 /*
7  * The purpose of snprintb is to produce a printable, visible representation
8  * of a binary number, therefore the description should consist of simple
9  * characters only, and these should not need to be escaped.  If they are,
10  * it's often due to a typo, such as a missing terminating '\0'.
11  */
12 
13 /* lint1-extra-flags: -X 351 */
14 
15 typedef typeof(sizeof(0)) size_t;
16 typedef unsigned long long uint64_t;
17 
18 int snprintb(char *, size_t, const char *, uint64_t);
19 
20 void
21 old_style_description(unsigned u32)
22 {
23 	char buf[64];
24 
25 	/* expect+6: warning: bit position '\t' in '\tprint' should be escaped as octal or hex [369] */
26 	/* expect+5: warning: escaped character '\377' in description of conversion '\nable\377' [363] */
27 	/* expect+4: warning: bit position '\n' in '\nable\377' should be escaped as octal or hex [369] */
28 	snprintb(buf, sizeof(buf),
29 	    "\020"
30 	    "\001non\tprint\nable\377",
31 	    u32);
32 
33 	/* expect+10: warning: escaped character '\177' in description of conversion '\002""\177' [363] */
34 	/* expect+9: warning: escaped character '\177' in description of conversion '\003aa""""\177' [363] */
35 	/* expect+8: warning: escaped character '\177' in description of conversion '\004""bb""\177' [363] */
36 	/* expect+7: warning: escaped character '\177' in description of conversion '\005""""cc\177' [363] */
37 	snprintb(buf, sizeof(buf),
38 	    "\020"
39 	    "\002""\177"
40 	    "\003aa""""\177"
41 	    "\004""bb""\177"
42 	    "\005""""cc\177",
43 	    u32);
44 
45 	/* expect+6: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */
46 	/* expect+5: warning: bit position '\n' in '\nable' should be escaped as octal or hex [369] */
47 	/* expect+4: warning: redundant '\0' at the end of the format [377] */
48 	snprintb(buf, sizeof(buf),
49 	    "\020"
50 	    "\001non\000print\nable\0",
51 	    u32);
52 }
53