msg_358.c revision 1.2 1 1.2 rillig /* $NetBSD: msg_358.c,v 1.2 2024/03/03 13:09:23 rillig Exp $ */
2 1.1 rillig # 3 "msg_358.c"
3 1.1 rillig
4 1.1 rillig // Test for message: hex escape '%.*s' has more than 2 digits [358]
5 1.1 rillig
6 1.1 rillig /*
7 1.1 rillig * In the format argument of the snprintb and snprintb_m functions, a bit
8 1.1 rillig * position or field width is written as an octal or hexadecimal escape
9 1.1 rillig * sequence. If the description that follows starts with hex digits (A-Fa-f),
10 1.1 rillig * these digits are still part of the escape sequence instead of the
11 1.1 rillig * description.
12 1.1 rillig */
13 1.1 rillig
14 1.1 rillig /* lint1-extra-flags: -X 351 */
15 1.1 rillig
16 1.1 rillig typedef typeof(sizeof(0)) size_t;
17 1.1 rillig typedef unsigned long long uint64_t;
18 1.1 rillig
19 1.1 rillig int snprintb(char*, size_t, const char*, uint64_t);
20 1.1 rillig
21 1.1 rillig void
22 1.1 rillig examples(unsigned u32, uint64_t u64)
23 1.1 rillig {
24 1.1 rillig char buf[64];
25 1.1 rillig
26 1.1 rillig /* expect+3: warning: hex escape '\x01B' has more than 2 digits [358] */
27 1.1 rillig snprintb(buf, sizeof(buf),
28 1.1 rillig "\020\x01BIT",
29 1.1 rillig u32);
30 1.1 rillig
31 1.1 rillig /* expect+3: warning: hex escape '\x01b' has more than 2 digits [358] */
32 1.1 rillig snprintb(buf, sizeof(buf),
33 1.1 rillig "\020\x01bit",
34 1.1 rillig u32);
35 1.1 rillig
36 1.1 rillig // This mismatch goes undetected as it has only 2 digits, does not mix
37 1.1 rillig // case and is in bounds. A spellchecker could mark the unknown word
38 1.1 rillig // 'ield' to give a hint.
39 1.1 rillig snprintb(buf, sizeof(buf),
40 1.1 rillig "\020\x1FIELD",
41 1.1 rillig u32);
42 1.1 rillig
43 1.1 rillig /* expect+3: warning: hex escape '\x01b' has more than 2 digits [358] */
44 1.1 rillig snprintb(buf, sizeof(buf),
45 1.1 rillig "\177\020b\x01bit\0",
46 1.1 rillig u64);
47 1.1 rillig
48 1.1 rillig /* expect+3: warning: hex escape '\x02b' has more than 2 digits [358] */
49 1.1 rillig snprintb(buf, sizeof(buf),
50 1.1 rillig "\177\020f\x00\x02bit\0",
51 1.1 rillig u64);
52 1.2 rillig
53 1.2 rillig // In this example from the snprintb manual page, the descriptions
54 1.2 rillig // that start with a hexadecimal digit must be separated from the
55 1.2 rillig // hexadecimal escape sequence for the bit position.
56 1.2 rillig snprintb(buf, sizeof(buf),
57 1.2 rillig "\20\x10NOTBOOT\x0f" "FPP\x0eSDVMA\x0cVIDEO"
58 1.2 rillig "\x0bLORES\x0a" "FPA\x09" "DIAG\x07" "CACHE"
59 1.2 rillig "\x06IOCACHE\x05LOOPBACK\x04" "DBGCACHE",
60 1.2 rillig u32);
61 1.1 rillig }
62