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