xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_167.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: msg_167.c,v 1.4 2022/06/16 16:58:36 rillig Exp $	*/
2 # 3 "msg_167.c"
3 
4 // Test for message: array subscript cannot be negative: %ld [167]
5 
6 void
7 example(int *ptr)
8 {
9 	int arr[6];
10 
11 	/* expect+1: warning: array subscript cannot be negative: -3 [167] */
12 	arr[-3] = 13;
13 
14 	/*
15 	 * Since the pointer may have been initialized with "arr + 3",
16 	 * subtracting from its address is allowed.
17 	 */
18 	ptr[-3] = 13;
19 }
20