xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_369.c (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /*	$NetBSD: msg_369.c,v 1.2 2024/03/02 11:56:37 rillig Exp $	*/
2 # 3 "msg_369.c"
3 
4 // Test for message: bit position '%.*s' in '%.*s' should be escaped as octal or hex [369]
5 
6 /*
7  * To distinguish bit positions from the description text, they should use
8  * octal or hex escape sequences.  Of these, octal escape sequences are less
9  * error-prone, as they consist of at most 3 octal digits, whereas hex escape
10  * sequences consume as many digits as available.
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 example(unsigned u32, uint64_t u64)
22 {
23 	char buf[64];
24 
25 	/* expect+8: warning: bit position ' ' in ' space' should be escaped as octal or hex [369] */
26 	/* expect+7: warning: bit position '\t' in '\ttab' should be escaped as octal or hex [369] */
27 	/* expect+6: warning: bit position '\n' in '\nnewline' should be escaped as octal or hex [369] */
28 	snprintb(buf, sizeof(buf),
29 	    "\020"
30 	    " space"
31 	    "\ttab"
32 	    "\nnewline",
33 	    u32);
34 
35 	/* expect+8: warning: bit position ' ' in 'b space\0' should be escaped as octal or hex [369] */
36 	/* expect+7: warning: bit position '\t' in 'b\ttab\0' should be escaped as octal or hex [369] */
37 	/* expect+6: warning: bit position '\n' in 'b\nnewline\0' should be escaped as octal or hex [369] */
38 	snprintb(buf, sizeof(buf),
39 	    "\177\020"
40 	    "b space\0"
41 	    "b\ttab\0"
42 	    "b\nnewline\0",
43 	    u64);
44 
45 	/* expect+6: warning: bit position '\t' in 'f\t\001tab\0' should be escaped as octal or hex [369] */
46 	/* expect+5: warning: bit position '\n' in 'F\n\001newline\0' should be escaped as octal or hex [369] */
47 	snprintb(buf, sizeof(buf),
48 	    "\177\020"
49 	    "f\t\001tab\0"
50 	    "F\n\001newline\0",
51 	    u64);
52 }
53