Fun Compo: Smallest Program that..
category: general [glöplog]
..crashes
So the rules are simple: Write the smallest possible C/C++ (or something different?) source that crashes when running it.. Must compile with one of the "standard" compilers (gcc, icc, vc, ..) though..
Thanx to one of my new colleagues for providing the idea for that!
I'm curious what you come up with..
So the rules are simple: Write the smallest possible C/C++ (or something different?) source that crashes when running it.. Must compile with one of the "standard" compilers (gcc, icc, vc, ..) though..
Thanx to one of my new colleagues for providing the idea for that!
I'm curious what you come up with..
what kind of crash are you looking for? A crash that causes a bluescreen, a crash that displays a error message, or what exactly?
And I hope entries like this are disqualified. :p
And I hope entries like this are disqualified. :p
Here's my entry:
Compiles in ASM-Pro.
Also, define "crash".
Code:
illegal
Compiles in ASM-Pro.
Also, define "crash".
Code:
int 3
debug
e 100 cc
n crash.com
rcx
1
w
q
(cc is the opcode for "int3")
e 100 cc
n crash.com
rcx
1
w
q
(cc is the opcode for "int3")
Code:
MZ
Did I win? I don't know if that runs... I'm not on windows now.
crash like "the program will be terminated because it did something the OS didn't like".. bluescreen would be even cooler.. ;)
and so far i didn't see any "real" programming language (asm and equal stuff is too "easy") here
and so far i didn't see any "real" programming language (asm and equal stuff is too "easy") here
main(){main();}
an example:
but this is a pretty long one actually..
Code:
void main(){int *p;p[0]=0;}
but this is a pretty long one actually..
okay.. something like ryg did.. cool one
ryg beat me to it while I was writing my post :(
So now I play it really dirty:
7 = pop es
So now I play it really dirty:
Code:
main=7;
7 = pop es
[code]void main(){int x=1/0;}
Code:
void main(){int x=1/0;}
freeke: if you want it really dirty, so be it!
but at least my original one was portable :)
Quote:
(save as c file, "works" with vc++/gcc :)main;
but at least my original one was portable :)
fr33ke wins i suppose.. or is there something even smaller??!
E9 FD FF ?
oh-- ryg was faster than me.. :)
Globals are initialized to zero so you get "add [byte ds:eax], al", but eax might contain a valid address. And who knows what will happen in the uninitalized space after that?
(alright, it will very probably crash, and _again_ you posted before I was ready writing that)
main(){main();} doesn't crash with -O2 btw, the tail recursion is optimized into a loop.
(alright, it will very probably crash, and _again_ you posted before I was ready writing that)
main(){main();} doesn't crash with -O2 btw, the tail recursion is optimized into a loop.
Code:
x;
VC > solution > properties > linker > advanced > entry point > "x"
Wow, Ger has gone even dirtier :o
gcc -Dq="int main(void){return 1/0;}"
Code:
q
gcc -Dq="int main(void){return 1/0;}"
fr33ke, it does crash with vc++ (even with /O2), so it counts i guess.
as for the "main;" version: three possibilities for a crash: 1. it crashes due to data execute prevention ("preferable"), 2. eax might contain an invalid address, 3. "random" code execution after that.
similarly, your "pop es" version might actually execute past that statement if the low 16 bits of the return address at that moment are a valid selector, so it also depends on somewhat random "outside" conditions.
safest way to *guarantee* a crash is probably division by zero/null pointer access, but both require "quite a lot of code" :)
as for the "main;" version: three possibilities for a crash: 1. it crashes due to data execute prevention ("preferable"), 2. eax might contain an invalid address, 3. "random" code execution after that.
similarly, your "pop es" version might actually execute past that statement if the low 16 bits of the return address at that moment are a valid selector, so it also depends on somewhat random "outside" conditions.
safest way to *guarantee* a crash is probably division by zero/null pointer access, but both require "quite a lot of code" :)
does the makefile count in the code size?
ryg: that said, while it is possible that it's a valid address, it is fairly unlikely that there's sensible code there?
Quote:
(that's empty)cl /link /nodefaultlib /entry:wsprintfA /subsystem:console user32.lib
ryg: damn, you're right. I thought changing the segment registers would always cause a fault since NT (it doesn't).