Shortest code that returns Segmentation Fault (SIGSEGV) in any programming language.
C, 5 characters
It's variable declaration - |
||||
|
|
pdfTeX (51)
This is actually probably a bug, but it is not present in the original TeX, written by Knuth: compiling the code with |
|||
|
|
3 Characters in Assembly
writing only this will give Segmentation Fault. |
|||||||||||||||||
|
Haskell, 31
This produces a segfault when compiled with GHC and run. No extension flags are needed, as the Foreign Function Interface is in the Haskell 2010 standard. |
|||
|
|
C -
|
|
|||
:Linker doesn't check whether main is function or not .It just pass it to the loader and return sigsegv – Arya Dec 26 '11 at 12:24 |
|||
|
Of course the last entry can be used for everything, you just have to supply the right compiler arguments. Which should make it the automatic winner of any code golf contest. :-) – celtschk Feb 4 '12 at 17:20 |
Perl, 10 / 12 charsA slightly cheatish solution is to shave one char off Joey Adams' bash trick:
However, to get a real segfault in Perl,
Technically, this isn't guaranteed to segfault, since the address 0x31313131 (or 0x3131313131313131 on 64-bit systems) just might point to valid address space by chance. But the odds are against it. Also, if perl is ever ported to platforms where pointers are longer than 64 bits, the |
|||
|
|
C# - 62
Edit: 23
Must compile with /unsafe for this one to work. For some reason I don't understand, |
|||||||
|
19 characters in C
It corrupts return address value of main function, so it gets a SIGSEGV on return of |
|||
|
Python, 33 characters
Source: http://bugs.python.org/issue1215#msg143236 Python, 60 characters
Source: http://svn.python.org/view/python/trunk/Lib/test/crashers/recursive_call.py?view=markup This is the Python version I'm testing on:
In general the Python interpreter is hard to crash, but the above is selective abusiveness... |
|||
|
|
Python 33
Sending signal 11 (SIGSEGV) in python. |
|||
|
|
Perl ( < 5.14 ), 9 chars
In 5.14 the regex engine was made reentrant so that it could not be crashed in this way, but 5.12 and earlier will segfault if you try this. |
|||
|
|
|
F90 - 25 chars
Compiled with Intel compiler 12.0 which actually refuses to compile without the intermediate n as it detects the bound error. Does this count as a segfault?:
|
|||
|
|