msg_366.c revision 1.5 1 1.5 rillig /* $NetBSD: msg_366.c,v 1.5 2024/08/31 06:57:31 rillig Exp $ */
2 1.1 rillig # 3 "msg_366.c"
3 1.1 rillig
4 1.1 rillig // Test for message: missing '\0' at the end of '%.*s' [366]
5 1.1 rillig
6 1.1 rillig /*
7 1.4 rillig * In the new-style format, each conversion ends with a '\0'. If that's not
8 1.1 rillig * the case, snprintb will read beyond the end of the format argument, looking
9 1.1 rillig * for the terminating '\0'. In the most common case where the format comes
10 1.4 rillig * from a string literal, the '\0' from the conversion needs to be spelled
11 1.4 rillig * out, while the '\0' that terminates the sequence of conversions is provided
12 1.4 rillig * by the C compiler.
13 1.1 rillig */
14 1.1 rillig
15 1.1 rillig /* lint1-extra-flags: -X 351 */
16 1.1 rillig
17 1.1 rillig typedef typeof(sizeof(0)) size_t;
18 1.1 rillig typedef unsigned long long uint64_t;
19 1.1 rillig
20 1.5 rillig int snprintb(char *, size_t, const char *, uint64_t);
21 1.1 rillig
22 1.1 rillig void
23 1.1 rillig example(unsigned u32)
24 1.1 rillig {
25 1.1 rillig char buf[64];
26 1.1 rillig
27 1.3 rillig /* expect+4: warning: redundant '\0' at the end of the format [377] */
28 1.1 rillig snprintb(buf, sizeof(buf),
29 1.1 rillig "\177\020"
30 1.1 rillig "\0",
31 1.1 rillig u32);
32 1.1 rillig
33 1.3 rillig /* expect+5: warning: empty description in 'b\007' [367] */
34 1.1 rillig /* expect+4: warning: missing '\0' at the end of 'b\007' [366] */
35 1.1 rillig snprintb(buf, sizeof(buf),
36 1.1 rillig "\177\020"
37 1.1 rillig "b\007",
38 1.1 rillig u32);
39 1.1 rillig
40 1.3 rillig /* expect+5: warning: empty description in 'f\007\000' [367] */
41 1.1 rillig /* expect+4: warning: missing '\0' at the end of 'f\007\000' [366] */
42 1.1 rillig snprintb(buf, sizeof(buf),
43 1.1 rillig "\177\020"
44 1.1 rillig "f\007\000",
45 1.1 rillig u32);
46 1.1 rillig
47 1.1 rillig /* expect+4: warning: missing '\0' at the end of 'F\007\000' [366] */
48 1.1 rillig snprintb(buf, sizeof(buf),
49 1.1 rillig "\177\020"
50 1.1 rillig "F\007\000",
51 1.1 rillig u32);
52 1.1 rillig
53 1.1 rillig /* expect+4: warning: missing '\0' at the end of '=\007value' [366] */
54 1.1 rillig snprintb(buf, sizeof(buf),
55 1.1 rillig "\177\020"
56 1.1 rillig "=\007value",
57 1.1 rillig u32);
58 1.1 rillig
59 1.1 rillig /* expect+4: warning: missing '\0' at the end of ':\007value' [366] */
60 1.1 rillig snprintb(buf, sizeof(buf),
61 1.1 rillig "\177\020"
62 1.1 rillig ":\007value",
63 1.1 rillig u32);
64 1.1 rillig
65 1.1 rillig /* expect+4: warning: missing '\0' at the end of '*default' [366] */
66 1.1 rillig snprintb(buf, sizeof(buf),
67 1.1 rillig "\177\020"
68 1.1 rillig "*default",
69 1.1 rillig u32);
70 1.1 rillig }
71