The Shortest Crashing C Program
11–20 of 94 posts
Re: The Shortest Crashing C Program
#12It 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
#13Re: The Shortest Crashing C Program
#14You could probably do the same thing in x86 and it'd work on a modern compiler.
Re: The Shortest Crashing C Program
#15Seems to work really well: It even crashed the website.
Re: The Shortest Crashing C Program
#16It 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
That's a shame. At least in one point in history, that was the shortest-known quine: http://www.ioccc.org/years.html#1994_smr
$ rm -rf a
$ cp a.c a
$ chmod +x a
$ ./a
$
Re: The Shortest Crashing C Program
#17I'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).
$ 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 function
[-Wmain]
$ /tmp/main
Segmentation fault (core dumped)Re: The Shortest Crashing C Program
#18I'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 can't be a valid C89 program. On many Harvard architecture based microprocessors data pointers and code pointers have differing size.
Re: The Shortest Crashing C Program
#19Re: The Shortest Crashing C Program
#20(If execution of bytes in the data segment were possible, which I'm sure it used to be, then you'd still likely get a crash, but it's not guaranteed. (uint32_t)0 is a valid sequence of instructions - it's ADD BYTE PTR [EAX],AL - and so if EAX contained a valid value then it would execute without a problem. Then, if the following byte were 0xC3 (RET) then the program would execute. OK, so that's all rather unlikely, but you have to bear these things in mind. So I think 0xCC (INT 3) would be a better choice.)