summaryrefslogtreecommitdiff
path: root/src/segfault.c
blob: 5863fa1230807e6789e51e08e4904f419d3344ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * segfault.c - a program that is intended to create a segmentation
 *              fault (SIGSEGV).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  That also
 * implies that it might not even segfault in the first place.
 *
 * No license - this code originates from Public Domain examples
 * on the internet. Not that I'd want to claim copyright anyway
 * on a program that is intended to crash in the first place.
 */

int main(void)
{
	char *s = "hello world";
	int *ptr = 0;

	/* you can't write to the static variable */
	*s = 'H';

	/* NULL ptr dereference */
	*ptr = 1;

	/* recurse without base (stack overflow) */
	main();

	return 0;
}