msg_357.c revision 1.2
1/*	$NetBSD: msg_357.c,v 1.2 2024/08/31 06:57:31 rillig Exp $	*/
2# 3 "msg_357.c"
3
4// Test for message: hex escape '%.*s' mixes uppercase and lowercase digits [357]
5
6/*
7 * In the format argument of the snprintb and snprintb_m functions, a bit
8 * position or field width is written as an octal or hexadecimal escape
9 * sequence.  If the description that follows starts with hex digits (A-Fa-f),
10 * these digits are still part of the escape sequence instead of the
11 * description.
12 *
13 * Since the escape sequences are typically written in lowercase and the
14 * descriptions are typically written in uppercase, a mixture of both cases
15 * indicates a mismatch.
16 */
17
18/* lint1-extra-flags: -X 351 */
19
20typedef typeof(sizeof(0)) size_t;
21typedef unsigned long long uint64_t;
22
23int snprintb(char *, size_t, const char *, uint64_t);
24
25void
26examples(unsigned u32, uint64_t u64)
27{
28	char buf[64];
29
30	/* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */
31	/* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */
32	/* expect+3: warning: bit position '\x0aB' (171) in '\x0aBIT' out of range 1..32 [371] */
33	snprintb(buf, sizeof(buf),
34	    "\020\x0aBIT",
35	    u32);
36
37	// This mismatch goes undetected as it has only 2 digits, does not mix
38	// case and is in bounds.  A spellchecker could mark the unknown word
39	// 'ield' to give a hint.
40	snprintb(buf, sizeof(buf),
41	    "\020\x1FIELD",
42	    u32);
43
44	/* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */
45	/* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */
46	/* expect+3: warning: bit position '\x0aB' (171) in 'b\x0aBIT\0' out of range 0..63 [371] */
47	snprintb(buf, sizeof(buf),
48	    "\177\020b\x0aBIT\0",
49	    u64);
50}
51