xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_302.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: msg_302.c,v 1.4 2022/06/22 19:23:18 rillig Exp $	*/
2 # 3 "msg_302.c"
3 
4 // Test for message: '%s' returns pointer to automatic object [302]
5 
6 void *
7 return_arg(int arg)
8 {
9 	/* expect+1: warning: 'return_arg' returns pointer to automatic object [302] */
10 	return &arg;
11 }
12 
13 void *
14 return_local(void)
15 {
16 	int local = 3;
17 	/* expect+1: warning: 'return_local' returns pointer to automatic object [302] */
18 	return &local;
19 }
20 
21 void *
22 return_local_array(_Bool cond)
23 {
24 	int local[5];
25 	int *p = local;
26 
27 	/* XXX: lint doesn't track this indirection, but Clang-tidy does. */
28 	if (cond)
29 		return p;
30 
31 	/* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */
32 	return local + 5;
33 }
34 
35 void *
36 return_static(void)
37 {
38 	static int long_lived = 3;
39 	return &long_lived;
40 }
41