msg_168.c revision 1.2
11.2Srillig/*	$NetBSD: msg_168.c,v 1.2 2021/01/24 16:12:45 rillig Exp $	*/
21.1Srillig# 3 "msg_168.c"
31.1Srillig
41.1Srillig// Test for message: array subscript cannot be > %d: %ld [168]
51.1Srillig
61.2Srilligvoid print_string(const char *);
71.2Srilligvoid print_char(char);
81.2Srillig
91.2Srilligvoid
101.2Srilligexample(void)
111.2Srillig{
121.2Srillig	char buf[20] = {};
131.2Srillig
141.2Srillig	print_string(buf + 19);	/* inside the array */
151.2Srillig
161.2Srillig	/*
171.2Srillig	 * It is valid to point at the end of the array, but reading a
181.2Srillig	 * character from there invokes undefined behavior.
191.2Srillig	 *
201.2Srillig	 * The pointer to the end of the array is typically used in (begin,
211.2Srillig	 * end) tuples.  These are more common in C++ than in C though.
221.2Srillig	 */
231.2Srillig	print_string(buf + 20);
241.2Srillig
251.2Srillig	print_string(buf + 21);	/* undefined behavior, not detected */
261.2Srillig
271.2Srillig	print_char(buf[19]);
281.2Srillig	print_char(buf[20]);	/* expect: 168 */
291.2Srillig}
30