Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Write programs that produce crazy, obscure, ridiculous, or just plain nutty runtime errors. Obfuscation and golfitude (shortness) not required.

  • solutions that look like they should work fine are better.
  • solutions that look like they should break one way but break another are better.
  • solutions that are nondeterministic are better as long as they are reproducible sometimes.
  • solutions with long distance between error cause and manifestation are better.
  • bonus points for producing errors that should be impossible.
  • bonus points for errors that crash the runtime (like making python segment fault) or operating system. *

The unit of score shall be upvotes.

Addendum 1

Compiler misbehaviors are fine too.

share|improve this question
1  
Making Python segfault is easy: import sys; sys.setrecursionlimit(~-2**31); x=lambda x:x(x); x(x); – marinus Aug 4 '12 at 1:53
Peter: whoops. I repurposed the question half way through writing it :S – Wug Aug 5 '12 at 23:48
...what about malbolge or INTERCAL? i'm pretty sure they'd have some pretty insane errors, probably can do it with a single char as well. – acolyte Aug 6 '12 at 21:26
This is definitely the best link to go for the solution: destroyallsoftware.com/talks/wat :-) – SeriTools.de - Dennis D. Aug 13 '12 at 17:50
I've seen that one. :D – Wug Aug 13 '12 at 18:04

4 Answers

The obligatory PHP one (which still hasn't been fixed as of 5.4):

<?::

Outputs:

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 1

Whaa?

share|improve this answer
3  
I do like this one. It might be my favorite error message. Apart from the one time my friend tried to boot his windows laptop to the recovery partition, and it turned the entire screen into a white box with giant red letters spelling "ERROR". – Wug Aug 4 '12 at 6:50
1  
Deliberate, but weird nevertheless: "Paamayim Nekudotayim would, at first, seem like a strange choice for naming a double-colon. However, while writing the Zend Engine 0.5 (which powers PHP 3), that's what the Zend team decided to call it. It actually does mean double-colon - in Hebrew!" php.net/manual/en/language.oop5.paamayim-nekudotayim.php – Jon Gauthier Aug 6 '12 at 1:50
3  
@HansEngel: Yes, it means double-colon in Hebrew. Using English for every token except this one makes sense because...? I guess I'd just have to ask the PHP team. – minitech Aug 6 '12 at 2:18

C(++)

If compile-time errors count here's one (assuming a file named "crash.c").

#include "crash.c"

int main(){ return 0; }

It fills the screen with this upon compilation (have Ctrl-C ready)

                 from crash.c:1,
                 from crash.c:1:
crash.c:3:1: error: redefinition of ‘main’
crash.c:3:1: note: previous definition of ‘main’ was here
In file included from crash.c:1:0,
                 from crash.c:1,
                 from crash.c:1,

Another snippet which compiles perfectly well (no warnings under -Wall and illustrates the beautiful type safety of C </s>

#include <stdio.h>
int i;

int main(){
  sprintf(NULL, "%s", (char *) (void *) (1/i));
  return 0;
}

Running it gives:

Floating point exception (core dumped)
share|improve this answer

I'll start:

#include <iostream>

using namespace std;

class A
{
public:
    A()
    {
    }

    void doSomethingDiabolical()
    {
        delete this;
    }

    virtual void breakHorribly()
    {
        cout << "still alive" << endl;
        doSomethingDiabolical();
        cout << "still alive" << endl;
    }
};

class B : public A
{
public:
    B() : A()
    {
    }

    void breakHorribly()
    {
        cout << "still alive" << endl;
        ((A *) this)->breakHorribly();
        cout << "still alive" << endl;
        doSomethingDiabolical();
        cout << "still alive" << endl;
        breakHorribly();
        cout << "dead" << endl;
    }
};

int main()
{
    jane();
}

void jane()
{
    cout << "still alive" << endl;
    A * o = new B;
    cout << "still alive" << endl;
    o->breakHorribly();
}

Any guesses why this program crashes? :D

See jane run: http://ideone.com/gtaZ3

share|improve this answer
1  
Isn't this a rather straightforward infinite recursion? B::BreakHorribly calls itself before doSomethingDiabolical is called, so delete this is never reached. – marinus Aug 4 '12 at 1:43
This program explodes for a large number of reasons. Its behavior changes if you remove different print statements. However, you're right. I didn't have the time to reproduce the undefined behavior I had once, but I ended up getting a pure virtual function call at runtime. – Wug Aug 4 '12 at 6:48
1  
You're not saying you once accidentally typed something like delete this, are you? – leftaroundabout Aug 5 '12 at 11:11
No, it was much more subtle than that, but the end result was the same: a destructor was called for a class during execution of a member function – Wug Aug 5 '12 at 23:45

How about compiler optimisation errors:

#include <stdio.h>

#define N 4

int main(void)
{
    int sum;
    int i;
    int arr[N];

    for (i = 0, sum = 0; i < N; i++, arr[i] = sum) {
        sum += arr[i];
    }
    printf("%d\n", sum);
    return 0;
}

This is specific to gcc >= 4.7. Compiles and runs fine with gcc -O0 -Wall. Compiles with gcc -O2 -Wall but results in an inf-loop.

Also note, how gcc does see the problem for smaller N, e.g. N = 3:

test.c:11:38: warning: array subscript is above array bounds [-Warray-bounds]
  for (i = 0, sum = 0; i < N; i++, arr[i] = sum) {
                                       ^
test.c:12:13: warning: 'arr[0]' is used uninitialized in this function [-Wuninitialized]
  sum += arr[i];
         ^

Btw, this has been taken from a bug report, I can't recall the bug number though.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.