The Shortest Crashing C Program

It might seem like a strange idea to want to write a small crashing C program, but in one of the courses that I’ve been teaching labs this is one of the tasks! It’s actually a very educational thing to do.

Usually students either try to dereference an invalid address, or divide by zero. Dividing by zero raises the SIGFPE signal (Floating Point Exception). Here is a small example program that crashes using divide-by-zero:

int main()
{
    return 1/0;
}

We could remove the return keyword but gcc refuses to generate code for the statement when I do this, even with optimization disabled. We can shave off a few characters from the above by transforming the statement into an assignment:

i;
int main()
{
    i=1/0;
}

Note that I have declared i without a type. This works in C89 because declarations have the implicit type int. In C99 and some other C variants this is an error. Let’s assume we’re writing C89 code, then we can even use implicit int for main:

i;
main()
{
    i=1/0;
}

That’s pretty short – 16 characters if we don’t count redundant whitespace. However, we can do better!

When a C program is compiled, the compiler creates one or more object files with symbolic references to libraries and global objects (functions and variables). The object files are then linked – symbolic references replaced by addresses – to create an executable.

The compiler provides an entry point that calls main in one of the object files. Calling main means that we try to execute the instructions at the address stored at the location main was linked to.

Interestingly, the linker has no concept of the types of different objects – it only knows of their addresses. So, if we replace main by a regular global variable, the compiler will happily build the object file because it does not care what type of object main is, and the linker will happily link it because it is only concerned with the address of main.

So, consider this C program:

int main=0;

This will compile to an executable that tries to call address 0, which is not an address that we have access to so we get the SIGSEGV signal (Segmentation Fault).

Now we’re very close to the smallest crashing C program. We can use the trick with implicit int to shorten it further.

main=0;

Also, global variables in C are initialized to zero implicitly, so this is equivalent:

main;

And there we have it, the shortest crashing C program!

Chunky Goals

Sometimes people ask me what I’m planning to work on in Chunky. I have a set of goals that I want to achieve, and a rough idea of what order I want to work on these goals.

My current goals are (ordered after approximate priority):

  • More Sky Options – control over sky light multiplier, custom sky color gradients, improved clouds, night mode, etc.
  • Material Editor – allow changing block textures, reflectance, emittance
  • Improved Scene Manager
  • Distributed Rendering
  • New CPU Renderer – add a renderer with better convergence rate for indoor scenes
  • OpenCL GPU Renderer
  • Entity Rendering – render paintings, mobs, boats etc.

That’s a big list. Many of those goals require a lot of work. The first item, More Sky Options, is what I’m planning for version 1.2, but when and in what order the others are implemented is undecided. Usually I am distracted by my job, bugfixes and minor features.

Chunky 1.1.8

I just released Chunky version 1.1.8. It fixes a texture loading problem caused by animated Minecraft 1.5 textures that some people were experiencing. I had planned to implement more things for version 1.1.8 but I want to get this bugfix out sooner rather than later. Since I will be away over Easter it would have taken at least a week until I could do the release if I didn’t do it now.

In 1.1.8 I’ve added a way of manually doing distributed rendering. It is now possible to merge render dumps into the current render, which means you can render simultaneously on a different machine, grab the dump and merge it into the current render. This does not work fully as it should right now, and it’s a bit tedious if you want to merge many dumps but at least it’s one first step towards distributed rendering. I used it while rendering the two Broville wallpapers from the previous post.

Here is the reddit release thread.

Building in Broville

My go-to Minecraft world for testing the 3D rendering in Chunky has been Broville v10 by Oldshoes & Co. Here is an early render I did of Broville v10 that shows how far Chunky has come since last summer:

oldshoes1

The first time I saw Broville was while browsing /v/. I believe it was 2010. It was the first time I saw anyone attempt to build a genuine city in Minecraft. This was back when Minecraft was still in alpha, and mostly I’d just seen people building isolated structures before that. Broville was intended to be one coherent city and that was pretty damn cool!

A couple weeks ago Oldshoes, the man behind Broville, gave me a tour of the Broville v11 project. Broville v11 is amazing, it completely blows Broville v10 out of the water! Unlike it’s predecessor, v11 is a complete reboot, the Broville team has started a new city from scratch rather than continuing to expand on the old one and it is looking incredibly good already. The new map is better planned than the old map and has a SimCity-esque feel to it.

Even though I do not play a lot of Minecraft myself, in fact the last time I really played Minecraft was in the spring of 2011, I have started building my own little hideout in Broville 11. I’m building a small hobbit hole in the forest outside the city, and though it may not seem as much on the outside it’s got some secrets inside!

I look forward to rendering the Broville 11 cityscape, but until then here are two wallpapers from the v10 map that I’ve been rendering for the past week:

Digital Archeology

My brother and I used to play on our own Minecraft server a couple years ago. My brother had already been working on a large fort so we loaded that up in a server and continued building. We had very grand plans, but never really got that far. My brother built a large wall meant to encircle a medieval village and keep. I built a ridiculously large church in the center, and under the church I dug a hole.

How big of a hole did I dig? Well, see for yourself:

Skull Cavern

This is a pretty impressive hole, but what makes it even more impressive is the fact that we played entirely in “Survival” mode – no cheats, everything tediously mined and crafted and dug. Many people have built larger and more impressive things in Minecraft, but that hole right there is my proudest Minecraft achievement.

I had a moment of nostalgia a couple days ago when I poked around on an old disused hard-drive and found this Minecraft world intact – I was somewhat worried that it had been lost.