Some programmers never learn. The following illustration depicts a delightful beach on a Caribbean island, a few seconds after the following line of code was executed:

Oh sh...

return strcpy(malloc(strlen(s)), s);

It's still a beach, but it's no longer quite so delightful.

This next one was a bit unfortunate. At a reunion of old army colleagues, one of our customers decided to show off his company's computing power by writing a program to organize the seating plan for the full-dress-uniform dinner to be held that evening.

What the f...

What a shame that he didn't cast ch to unsigned char when he wrote ch = toupper(ch);

Still, on this occasion he didn't survive the experience, so this doesn't count as a repetitive fault.

This is one of our favourites. The value of NULL on a DeathStation 9000 varies from one compile to the next. It might be all-bits-zero and it might not. So this code: memset(&weapon, 0, sizeof weapon); wasn't quite as robust as it might have been, as a result of which, a certain city in mid-West America got a nasty surprise (this one had to be hushed up, which is why we can't name the (ex-)city):

Oh bugger...


So when the manual says 'don't invoke undefined behaviour', it's serious, okay?

Think design...


This is a lovely picture of the US military testing their rocket targeting system on a portable DeathStation 9000. What the picture doesn't show is that, 12 seconds later, that outbound missile had become an inbound missile. This underlines the importance of rigorous algorithm design and evaluation. The program code had no undefined behaviour at all. The algorithm was simple; launch, count to 6 and then hit the nearest hot target. (oops)

It's not just our customers who get it wrong. A few days ago, we were testing the latest improvement in the design of our Demon air-to-air missiles. One of our programmers had allocated a huge character buffer so that he could use gets() to capture a keypress. He thought 8192 bytes would be enough. Unfortunately, the operator responsible for entering this keypress had fallen asleep at the keyboard (he later claimed he was suffering from radiation sickness, but we don't accept this at all. He's rarely exposed to more than 300R per day). His nose held the spacebar down for a few minutes. As a consequence, we would like to apologise to the relatives of anyone living in a number of cities in Texas, Arizona, California, and Cuba (sorry, Castro - believe us, this was an accident (this time)). We're not too worried about apologising to the ex-citizens of Redmond, WA, however. It's their own fault for living there in the first place. As Kaz said at the time, "I ran it on my DeathStation 9000, and Demons flew out of my NOSE".