pouët.net

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..
added on the 2007-11-17 16:42:44 by toxie toxie
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
added on the 2007-11-17 16:49:16 by micksam7 micksam7
Here's my entry:

Code: illegal


Compiles in ASM-Pro.

Also, define "crash".
added on the 2007-11-17 16:50:23 by doomdoom doomdoom
Code:int 3
added on the 2007-11-17 16:52:11 by Gargaj Gargaj
debug
e 100 cc
n crash.com
rcx
1
w
q

(cc is the opcode for "int3")
added on the 2007-11-17 16:59:51 by ryg ryg
Code:MZ


Did I win? I don't know if that runs... I'm not on windows now.
added on the 2007-11-17 17:39:33 by xernobyl xernobyl
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
added on the 2007-11-17 17:42:17 by toxie toxie
main(){main();}
added on the 2007-11-17 17:46:23 by ryg ryg
an example:
Code: void main(){int *p;p[0]=0;}

but this is a pretty long one actually..
added on the 2007-11-17 17:46:34 by toxie toxie
okay.. something like ryg did.. cool one
added on the 2007-11-17 17:48:20 by toxie toxie
ryg beat me to it while I was writing my post :(
So now I play it really dirty:
Code:main=7;

7 = pop es
added on the 2007-11-17 18:09:20 by fr33ke fr33ke
[code]void main(){int x=1/0;}
added on the 2007-11-17 18:12:36 by src src
Code:void main(){int x=1/0;}
added on the 2007-11-17 18:13:50 by src src
freeke: if you want it really dirty, so be it!
Quote:
main;
(save as c file, "works" with vc++/gcc :)
but at least my original one was portable :)
added on the 2007-11-17 18:17:30 by ryg ryg
fr33ke wins i suppose.. or is there something even smaller??!
added on the 2007-11-17 18:18:06 by toxie toxie
E9 FD FF ?
added on the 2007-11-17 18:19:10 by red red
oh-- ryg was faster than me.. :)
added on the 2007-11-17 18:19:16 by toxie toxie
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.
added on the 2007-11-17 18:25:34 by fr33ke fr33ke
Code: x;

VC > solution > properties > linker > advanced > entry point > "x"
added on the 2007-11-17 18:27:16 by Ger Ger
Wow, Ger has gone even dirtier :o
Code:q

gcc -Dq="int main(void){return 1/0;}"
added on the 2007-11-17 18:37:41 by fr33ke fr33ke
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" :)
added on the 2007-11-17 18:39:11 by ryg ryg
does the makefile count in the code size?
added on the 2007-11-17 18:41:56 by Gargaj Gargaj
ryg: that said, while it is possible that it's a valid address, it is fairly unlikely that there's sensible code there?
added on the 2007-11-17 18:44:04 by Gargaj Gargaj
Quote:
(that's empty)
cl /link /nodefaultlib /entry:wsprintfA /subsystem:console user32.lib
added on the 2007-11-17 18:48:03 by ryg ryg
ryg: damn, you're right. I thought changing the segment registers would always cause a fault since NT (it doesn't).
added on the 2007-11-17 18:48:27 by fr33ke fr33ke

login