How about: main(){*(int*)0=0;} or: main(){*""=0;} or: main(){main();}
The Shortest Crashing C Program
41–50 of 94 posts
Re: The Shortest Crashing C Program
#42I'm not convinced this is a C89 program. It is only an "accident" that the linker doesn't know about types. I find it hard to believe that the C89 spec states that an integer called "main" is to be considered the main function, and suspect this is undefined behaviour (though I've not checked).
It compiles and runs with gcc -std=c89 and gcc -std=c99, so even if it's not a true C89 program, it's a compilable GNUC89 program. $ gcc -std=c99 -pedantic /tmp/main.c -o /tmp/main /tmp/main.c:1:1: warning: data definition has no type or storage class [enabled by default] /tmp/main.c:1:1: warning: type defaults to ‘int’ in declaration of ‘main’ [enabled by default] /tmp/main.c:1:1: warning: ‘main’ is usually a functi…
gcc -nostdlib -std=c89 a.c -o a
a.c:1: warning: data definition has no type or storage class
Undefined symbols for architecture x86_64:
"start", referenced from:
-u command line option
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status`Re: The Shortest Crashing C Program
#43How about: main(){*(int*)0=0;} or: main(){*""=0;} or: main(){main();}
Edit: deleted because I got to the Google cache and that's what the site was suggesting.
Re: The Shortest Crashing C Program
#44How about: main(){*(int*)0=0;} or: main(){*""=0;} or: main(){main();}
Edit: deleted because I got to the Google cache and that's what the site was suggesting.
Re: The Shortest Crashing C Program
#45EDIT: this is wrong, see below.
That's wrong. 'static' variables are initialized to zero. Non-static variables are un-initialized, so they have a "random" value.
See:
$ valgrind ./a.out
==5118== Memcheck, a memory error detector
==5118== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==5118== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==5118== Command: ./a.out
==5118==
==5118==
==5118== Process terminating with default action of signal 11 (SIGSEGV)
==5118== Bad permissions for mapped region at address 0x600864
==5118== at 0x600864: ??? (in /home/def/a.out)
==5118== by 0x4E54A14: (below main) (in /usr/lib/libc-2.17.so)
Re: The Shortest Crashing C Program
#46> Also, global variables in C are initialized to zero implicitly, so this is equivalent: EDIT: this is wrong, see below. That's wrong. 'static' variables are initialized to zero. Non-static variables are un-initialized, so they have a "random" value. See: $ valgrind ./a.out ==5118== Memcheck, a memory error detector ==5118== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==5118== Using Valgrind-3.8.1…
Re: The Shortest Crashing C Program
#47It depends on the definition. You can do better than this if you define a valid C program as anything that passes though the C compiler and generates an executable. Behold the zero length program: $ touch a.c $ gcc -c a.c $ ld a.o ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078 $ ./a.out Segmentation fault
Re: The Shortest Crashing C Program
#48> Also, global variables in C are initialized to zero implicitly, so this is equivalent: EDIT: this is wrong, see below. That's wrong. 'static' variables are initialized to zero. Non-static variables are un-initialized, so they have a "random" value. See: $ valgrind ./a.out ==5118== Memcheck, a memory error detector ==5118== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==5118== Using Valgrind-3.8.1…
But global variables are static.
Re: The Shortest Crashing C Program
#49Seems to work really well: It even crashed the website.
Re: The Shortest Crashing C Program
#50> Also, global variables in C are initialized to zero implicitly, so this is equivalent: EDIT: this is wrong, see below. That's wrong. 'static' variables are initialized to zero. Non-static variables are un-initialized, so they have a "random" value. See: $ valgrind ./a.out ==5118== Memcheck, a memory error detector ==5118== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==5118== Using Valgrind-3.8.1…
Global(variables at file scope) and variables with static linkage (i.e. the static keyword) both of have static storage duration.