At the office we have this joke, that the shortest program, that produces “Segmentation fault” is:

$ echo Segmentation fault (core dumped)
Segmentation fault (core dumped)

We had this joke, after a collegue of ours debugged that exact program for 20min, before he realized that it actually printed sefgault :)

However, one of the collegues decided to challenge that and he wrote this piece of code:

$ echo 'int main() { int *i=0; *i=0; }' | g++ -x c++ - ; ./a.out
Segmentation fault (core dumped)

At that point I jumped in, and “optimized it” :) :

$ echo 'int main(){int *i;*i=0;}'|g++ -x c++ -;./a.out

We had another “optimization”:

$ echo 'main(){int*i;*i=0;}'|g++ -x c++ -;./a.out

Then the first collegue decided that it would be easier in shell:

sh -c 'kill -11 $$'

I manged to make another optimization :) :

$ sh $(kill -11 $$)

In the end, one college from our Plovdiv office decided to share with us, this link :)


Comments are closed.

Posted by HackMan
Dated: 4th November 2019
Filled Under: Uncategorized