msg_377.c revision 1.2 1 /* $NetBSD: msg_377.c,v 1.2 2024/03/03 10:27:18 rillig Exp $ */
2 # 3 "msg_377.c"
3
4 // Test for message: redundant '\0' at the end of the format [377]
5
6 /*
7 * Each directive in the new-style format ends with a '\0' that needs to be
8 * spelled out.
9 *
10 * In both old-style and new-style formats, the '\0' that ends the whole
11 * format is provided by the compiler as part of the string literal.
12 */
13
14 /* lint1-extra-flags: -X 351 */
15
16 typedef typeof(sizeof(0)) size_t;
17 typedef unsigned long long uint64_t;
18
19 int snprintb(char*, size_t, const char*, uint64_t);
20
21 void
22 example(unsigned u32, uint64_t u64)
23 {
24 char buf[64];
25
26 /* expect+9: warning: old-style format contains '\0' [362] */
27 /* expect+8: warning: old-style format contains '\0' [362] */
28 /* expect+7: warning: bit position '\000' (0) in '\000out-of-range' out of range 1..32 [371] */
29 /* expect+6: warning: redundant '\0' at the end of the format [377] */
30 snprintb(buf, sizeof(buf),
31 "\020"
32 "\005bit"
33 "\000out-of-range"
34 "\0",
35 u32);
36
37 /* expect+5: warning: redundant '\0' at the end of the format [377] */
38 snprintb(buf, sizeof(buf),
39 "\177\020"
40 "b\005bit\0"
41 "\0",
42 u64);
43 }
44