summaryrefslogtreecommitdiff
path: root/tests/usr.bin/xlint/lint1/msg_167.c
blob: 7a71a76ac82cf356912f00301fb26689f9d40e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*	$NetBSD: msg_167.c,v 1.5 2023/07/07 19:45:22 rillig Exp $	*/
# 3 "msg_167.c"

// Test for message: array subscript cannot be negative: %ld [167]

/* lint1-extra-flags: -X 351 */

void
example(int *ptr)
{
	int arr[6];

	/* expect+1: warning: array subscript cannot be negative: -3 [167] */
	arr[-3] = 13;

	/*
	 * Since the pointer may have been initialized with "arr + 3",
	 * subtracting from its address is allowed.
	 */
	ptr[-3] = 13;
}