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