xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_158.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: msg_158.c,v 1.3 2021/03/16 23:39:41 rillig Exp $	*/
2 # 3 "msg_158.c"
3 
4 // Test for message: %s may be used before set [158]
5 
6 void sink_int(int);
7 
8 void
9 example(int arg)
10 {
11 	int twice_arg;
12 
13 	sink_int(twice_arg);	/* expect: 158 */
14 	twice_arg = 2 * arg;
15 	sink_int(twice_arg);
16 }
17 
18 void
19 conditionally_used(int arg)
20 {
21 	int twice_arg;
22 
23 	if (arg > 0)
24 		twice_arg = 2 * arg;
25 	if (arg > 0)
26 		sink_int(twice_arg);
27 }
28 
29 void
30 conditionally_unused(int arg)
31 {
32 	int twice_arg;
33 
34 	if (arg > 0)
35 		twice_arg = 2 * arg;
36 
37 	/*
38 	 * This situation is not detected by lint as it does not track the
39 	 * possible code paths for all conditions.
40 	 */
41 	if (arg < 0)
42 		sink_int(twice_arg);
43 }
44