The Penny That Cost a Fortune: A Museum of Boundary Bugs That Made It to Production
Photo: Shixart1985, CC BY 2.0, via Wikimedia Commons
Somewhere in your codebase right now, there's a loop that runs one time too many. Or one time too few. Nobody has noticed yet. That's not a guess — that's a statistical certainty, like death, taxes, and a junior dev suggesting we rewrite the backend in Rust.
The off-by-one error is the common cold of software engineering: everyone gets it, no one's proud of it, and occasionally it develops into full-blown pneumonia and takes down a Fortune 500. Today we're visiting the museum of the worst ones. Please don't touch the exhibits. Some of them are still technically in production.
The Calendar That Ate February
In 2010, millions of older iPhones and Zunes woke up on New Year's Eve and decided the date was, logically, the 32nd of December. Microsoft's Zune bug became the folk legend, but the root cause is beautifully stupid: a leap-year calculation that checked whether the year was a multiple of 4, then 100, then 400 — and on the last day of a leap year, the day counter rolled past the boundary and the device, in the immortal words of every incident report ever written, "entered an unexpected state."
Unexpected state. That's what we call it when a computer refuses to acknowledge that December 32nd is not a thing. The fix was to let the battery drain. The lesson was free.
When a Penny Is a Policy Problem
Here's one that doesn't get enough respect: rounding. Any system that converts between currencies, splits payments, or calculates interest has to decide what to do with the half-cent. And any system that rounds inconsistently across two services will, given enough transactions, produce a discrepancy that accounting will eventually find with a flashlight and a grudge.
There are documented cases — most famously in trading systems — where floating-point rounding and boundary conditions in loop ranges caused positions to be off by fractions of a cent per trade. Run that math across millions of trades and you're not talking about a bug anymore. You're talking about a restatement of earnings. Somewhere at one of these firms, a developer wrote i < prices.length when they meant <= and changed the net worth of the company by an amount that required a PowerPoint to explain.
The Hyphen That Downed a Rocket
You knew we'd get here. The 1999 Mars Climate Orbiter is the unit-conversion bug everyone cites, but the Ariane 5 explosion in 1996 is the boundary bug's finest hour: a 64-bit floating point number was crammed into a 16-bit signed integer, the conversion overflowed, and the rocket's guidance system decided that the reasonable response was to self-destruct $370 million of hardware in about 40 seconds.
The value being converted? A horizontal velocity measurement that Ariane 4 never would have produced, but Ariane 5 flew faster. The code worked fine for years. It worked fine right up until it didn't. That's the part that should keep you up at night — not that the bug existed, but that it had a long, successful career before its dramatic retirement.
The Museum Gift Shop
So what's the takeaway, besides a vague dread every time you write a for loop?
Test the edges, not the middle. Every one of these bugs lived comfortably in the happy path for months. They died at the boundary — the last day of the year, the fastest the rocket would fly, the trade size nobody expected.
Off-by-one errors are really off-by-context errors. The code isn't wrong in a vacuum. It's wrong in the specific case nobody thought to ask about. December 31st of a leap year. The last element of the array. The customer with exactly one item in their cart.
And finally: you have shipped one. Maybe it rounded a report wrong. Maybe a cron job ran 61 times instead of 60. Maybe it's still out there, a tiny off-by-one ghost, quietly miscounting something no one has audited. The best you can do — the only thing any of us can do — is write the boundary tests, add the fuzzing, and accept that somewhere between index 0 and length, humility lives.
Off by one. Off by a little. Off by everything. The distance is smaller than you think, and the museum is always accepting new exhibits.