xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_370.c (revision 465ab238788e2dd3555edb0497148fa4c5f47dc7)
1*465ab238Srillig /*	$NetBSD: msg_370.c,v 1.3 2024/08/31 06:57:31 rillig Exp $	*/
238c0bdf2Srillig # 3 "msg_370.c"
338c0bdf2Srillig 
438c0bdf2Srillig // Test for message: field width '%.*s' in '%.*s' should be escaped as octal or hex [370]
538c0bdf2Srillig 
638c0bdf2Srillig /*
738c0bdf2Srillig  * To distinguish field widths from the description text, they should use
838c0bdf2Srillig  * octal or hex escape sequences.  Of these, octal escape sequences are less
938c0bdf2Srillig  * error-prone, as they consist of at most 3 octal digits, whereas hex escape
1038c0bdf2Srillig  * sequences consume as many digits as available.
1138c0bdf2Srillig  */
1238c0bdf2Srillig 
1338c0bdf2Srillig /* lint1-extra-flags: -X 351 */
1438c0bdf2Srillig 
1538c0bdf2Srillig typedef typeof(sizeof(0)) size_t;
1638c0bdf2Srillig typedef unsigned long long uint64_t;
1738c0bdf2Srillig 
1838c0bdf2Srillig int snprintb(char *, size_t, const char *, uint64_t);
1938c0bdf2Srillig 
2038c0bdf2Srillig void
2138c0bdf2Srillig example(uint64_t u64)
2238c0bdf2Srillig {
2338c0bdf2Srillig 	char buf[64];
2438c0bdf2Srillig 
2538c0bdf2Srillig 	/* expect+11: warning: bit position ' ' in 'f  space\0' should be escaped as octal or hex [369] */
2638c0bdf2Srillig 	/* expect+10: warning: field width ' ' in 'f  space\0' should be escaped as octal or hex [370] */
2738c0bdf2Srillig 	/* expect+9: warning: bit position '\t' in 'f\t\ttab\0' should be escaped as octal or hex [369] */
2838c0bdf2Srillig 	/* expect+8: warning: field width '\t' in 'f\t\ttab\0' should be escaped as octal or hex [370] */
2938c0bdf2Srillig 	/* expect+7: warning: bit position '\n' in 'f\n\nnewline\0' should be escaped as octal or hex [369] */
3038c0bdf2Srillig 	/* expect+6: warning: field width '\n' in 'f\n\nnewline\0' should be escaped as octal or hex [370] */
3138c0bdf2Srillig 	snprintb(buf, sizeof(buf),
3238c0bdf2Srillig 	    "\177\020"
3338c0bdf2Srillig 	    "f  space\0"
3438c0bdf2Srillig 	    "f\t\ttab\0"
3538c0bdf2Srillig 	    "f\n\nnewline\0",
3638c0bdf2Srillig 	    u64);
371ec17c71Srillig 	/* expect-1: warning: 'f\n\nnewline\0' overlaps earlier 'f\t\ttab\0' on bit 10 [376] */
3838c0bdf2Srillig 
3938c0bdf2Srillig 	/* expect+11: warning: bit position ' ' in 'F  space\0' should be escaped as octal or hex [369] */
4038c0bdf2Srillig 	/* expect+10: warning: field width ' ' in 'F  space\0' should be escaped as octal or hex [370] */
4138c0bdf2Srillig 	/* expect+9: warning: bit position '\t' in 'F\t\ttab\0' should be escaped as octal or hex [369] */
4238c0bdf2Srillig 	/* expect+8: warning: field width '\t' in 'F\t\ttab\0' should be escaped as octal or hex [370] */
4338c0bdf2Srillig 	/* expect+7: warning: bit position '\n' in 'F\n\nnewline\0' should be escaped as octal or hex [369] */
4438c0bdf2Srillig 	/* expect+6: warning: field width '\n' in 'F\n\nnewline\0' should be escaped as octal or hex [370] */
4538c0bdf2Srillig 	snprintb(buf, sizeof(buf),
4638c0bdf2Srillig 	    "\177\020"
4738c0bdf2Srillig 	    "F  space\0"
4838c0bdf2Srillig 	    "F\t\ttab\0"
4938c0bdf2Srillig 	    "F\n\nnewline\0",
5038c0bdf2Srillig 	    u64);
511ec17c71Srillig 	/* expect-1: warning: 'F\n\nnewline\0' overlaps earlier 'F\t\ttab\0' on bit 10 [376] */
5238c0bdf2Srillig }
53