xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_363.c (revision ce2046810387440872bfc20878728c18e4f27f6c)
1*ce204681Srillig /*	$NetBSD: msg_363.c,v 1.7 2024/11/05 06:23:04 rillig Exp $	*/
238c0bdf2Srillig # 3 "msg_363.c"
338c0bdf2Srillig 
4dae6022bSrillig // Test for message: escaped character '%.*s' in description of conversion '%.*s' [363]
538c0bdf2Srillig 
638c0bdf2Srillig /*
738c0bdf2Srillig  * The purpose of snprintb is to produce a printable, visible representation
8dae6022bSrillig  * of a binary number, therefore the description should consist of simple
9dae6022bSrillig  * characters only, and these should not need to be escaped.  If they are,
10dae6022bSrillig  * it's often due to a typo, such as a missing terminating '\0'.
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 old_style_description(unsigned u32)
2238c0bdf2Srillig {
2338c0bdf2Srillig 	char buf[64];
2438c0bdf2Srillig 
2538c0bdf2Srillig 	/* expect+6: warning: bit position '\t' in '\tprint' should be escaped as octal or hex [369] */
26dae6022bSrillig 	/* expect+5: warning: escaped character '\377' in description of conversion '\nable\377' [363] */
2738c0bdf2Srillig 	/* expect+4: warning: bit position '\n' in '\nable\377' should be escaped as octal or hex [369] */
2838c0bdf2Srillig 	snprintb(buf, sizeof(buf),
2938c0bdf2Srillig 	    "\020"
3038c0bdf2Srillig 	    "\001non\tprint\nable\377",
3138c0bdf2Srillig 	    u32);
3238c0bdf2Srillig 
33*ce204681Srillig 	// In the new format, the description can technically contain
34*ce204681Srillig 	// arbitrary characters, but having non-printable characters would
35*ce204681Srillig 	// produce confusing output, so any escaped characters are suspicious
36*ce204681Srillig 	// of being unintended.
37*ce204681Srillig 	/* expect+6: warning: escaped character '\t' in description of conversion 'b\000non\t' [363] */
38*ce204681Srillig 	/* expect+5: warning: escaped character '\n' in description of conversion 'b\000non\tprint\n' [363] */
39*ce204681Srillig 	/* expect+4: warning: escaped character '\377' in description of conversion 'b\000non\tprint\nable\377' [363] */
40*ce204681Srillig 	snprintb(buf, sizeof(buf),
41*ce204681Srillig 	    "\177\020"
42*ce204681Srillig 	    "b\000non\tprint\nable\377\0",
43*ce204681Srillig 	    u32);
44*ce204681Srillig 
45dae6022bSrillig 	/* expect+10: warning: escaped character '\177' in description of conversion '\002""\177' [363] */
46dae6022bSrillig 	/* expect+9: warning: escaped character '\177' in description of conversion '\003aa""""\177' [363] */
47dae6022bSrillig 	/* expect+8: warning: escaped character '\177' in description of conversion '\004""bb""\177' [363] */
48dae6022bSrillig 	/* expect+7: warning: escaped character '\177' in description of conversion '\005""""cc\177' [363] */
4959263861Srillig 	snprintb(buf, sizeof(buf),
5059263861Srillig 	    "\020"
5159263861Srillig 	    "\002""\177"
5259263861Srillig 	    "\003aa""""\177"
5359263861Srillig 	    "\004""bb""\177"
5459263861Srillig 	    "\005""""cc\177",
5559263861Srillig 	    u32);
5659263861Srillig 
573d5fc263Srillig 	/* expect+6: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */
5838c0bdf2Srillig 	/* expect+5: warning: bit position '\n' in '\nable' should be escaped as octal or hex [369] */
59a8d07ea3Srillig 	/* expect+4: warning: redundant '\0' at the end of the format [377] */
6038c0bdf2Srillig 	snprintb(buf, sizeof(buf),
6138c0bdf2Srillig 	    "\020"
6238c0bdf2Srillig 	    "\001non\000print\nable\0",
6338c0bdf2Srillig 	    u32);
6438c0bdf2Srillig }
65