3 ms·
Way back in the 1990s, I had to deal with a null-vs-0 bug in C. It was caused by the Sybase API for BLOBs, along with some careless programming by someone years
by beat 8y ago
Way back in the 1990s, I had to deal with a null-vs-0 bug in C. It was caused by the Sybase API for BLOBs, along with some careless programming by someone years before me.
Sybase, at least back then, stored BLOBs as 8k chunks. So when creating a row, if you passed NULL (in C) for the pointer to the data to store in the BLOB, then the BLOB became null. But if you passed 0 as the pointer, then Sybase allocated 8k and stored an empty value.
For years, we had stored data in BLOB fields, sometimes empty. We'd never noticed the 8k allocation into empty fields, because it was swamped by the ones with real data. But we pulled the data out into files and added a file name field to find it (for performance reasons), and adjusted the size of the databases, because disk was expensive back then!
I had implemented the transition, and had argued for removal of the BLOB column entirely, but our cautious lead dev rejected it, out of fear the missing column would break other things. Testing showed everything working perfectly. Then we put it into production...
...and saw that we had about four hours before we ran out of rapidly-filling database space. And we could not gracefully roll back, for business reasons. So I had four hours to find and fix the bug.
The real problem here wasn't NULL itself. That was a reasonable way to communicate a state to Sybase. But other problems made it a problem. First, the C programmer's habit of treating 0 and null pointers interchangeably. They are usually but not always equivalent! This bug had actually been sitting latent in our system for five years at that point - we just never noticed it.
The other problem was the lava flow antipattern, not removing a clearly unnecessary database field out of fear of downstream repercussions. That one bothers me more, and to this day, I try to be good about not keeping apparently-dead code out of fear.