xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_361.c (revision ce2046810387440872bfc20878728c18e4f27f6c)
1 /*	$NetBSD: msg_361.c,v 1.4 2024/11/05 06:23:04 rillig Exp $	*/
2 # 3 "msg_361.c"
3 
4 // Test for message: number base '%.*s' is %ju, must be 8, 10 or 16 [361]
5 
6 /*
7  * The first or second character of the snprintb format specifies the number
8  * base.  It must be given as an octal or hexadecimal escape sequence.
9  */
10 
11 /* lint1-extra-flags: -X 351 */
12 
13 typedef typeof(sizeof(0)) size_t;
14 typedef unsigned long long uint64_t;
15 
16 int snprintb(char *, size_t, const char *, uint64_t);
17 
18 void
19 old_style_number_base(void)
20 {
21 	char buf[64];
22 
23 	/* expect+1: warning: missing new-style '\177' or old-style number base [359] */
24 	snprintb(buf, sizeof(buf), "", 0);
25 	/* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */
26 	snprintb(buf, sizeof(buf), "\002", 0);
27 	snprintb(buf, sizeof(buf), "\010", 0);
28 	snprintb(buf, sizeof(buf), "\n", 0);
29 	snprintb(buf, sizeof(buf), "\020", 0);
30 	/* expect+1: warning: number base '\014' is 12, must be 8, 10 or 16 [361] */
31 	snprintb(buf, sizeof(buf), "" "\014" "", 0);
32 	snprintb(buf, sizeof(buf), "" "\020" "", 0);
33 }
34 
35 void
36 new_style_number_base(void)
37 {
38 	char buf[64];
39 
40 	/* expect+1: warning: missing new-style number base after '\177' [360] */
41 	snprintb(buf, sizeof(buf), "\177", 0);
42 	/* expect+1: warning: number base '\0' is 0, must be 8, 10 or 16 [361] */
43 	snprintb(buf, sizeof(buf), "\177\0", 0);
44 	/* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */
45 	snprintb(buf, sizeof(buf), "\177\002", 0);
46 	snprintb(buf, sizeof(buf), "\177\010", 0);
47 	snprintb(buf, sizeof(buf), "\177\n", 0);
48 	snprintb(buf, sizeof(buf), "\177\020", 0);
49 	/* expect+1: warning: number base '\014' is 12, must be 8, 10 or 16 [361] */
50 	snprintb(buf, sizeof(buf), "" "\177\014" "", 0);
51 	snprintb(buf, sizeof(buf), "" "\177\020" "", 0);
52 }
53