Gray Watson Personal Thoughts 2002.07.01
Bugs of All Time

Just came across another excellent bug (programming error) and I thought I should starting writing them down because there have been some great ones over the years. Needless to say this is going to be less than interesting to non programmers and even hackers may not care.

  1. [20071229] One of my favorite bugs happened to me last year as I was coming up to speed with Java. In writing a hashCode() method one day, I was using the HashCodeBuilder() cool helper class. It allows you to append all of the fields and it then derives a hashcode for the object. Unfortunately, instead of calling toHashCode() at the end, I was calling hashCode() which returned the hashCode() of the HashCodeBuilder object, not of the object I was trying to hash. Took a lot of staring at the screen to get that one.
  2. [20061231] Just remembered a classic error in the libc of Digital Unit (or True64, ...). I was using printf's "%.*s" format to print the first 10 characters of the string. The problem was that they were doing a strlen first on the string. This wouldn't be a problem except that I was dealing with a mmap'd block of memory without a null character until the strlen did an illegal access. After 3 months DEC called me back saying that after a number of meetings they agree with me that it is a bug -- thanks for nothing. Took them another 6 months to fix it in a release. Here's the call log I wrote about the incident.
  3. Back when I had my own [failed] software company, Raju, one of my guys, came to me with a really strange bug. We put the function in a debugger and watched as a local variable was changed by a call to scanf. The problem was that nowhere in the scanf line was the variable referenced. This, like many other times, I was convinced it was a compiler bug -- riiiiight. Turns out that the scanf was missing its last pointer argument and for some reason, the address of the local variable was on the stack. Oh the power of C. :-)
  4. Back when I worked at the University of Pittsburgh, my boss did a lot of coding. He was a self taught software engineer and was pretty darn good. But this one time, he had a macro which had a local variable named i. Unfortunately for him, he used this macro once with an argument for a variable named i. So the macro did absolutely nothing since the scope of the internal local i, stepped on the outer one. For that reason, you should always put underscores (_) at the front of local variables in macros.
  5. Back in Pittsburgh, one of our guys was working with my hash-table library. He came to me complaining that there was a bug in it after fighting with a debugger for a while. I told him that it was used far, far too often for there to be a problem. After fighting it for a while more, it turned out that there was a bug in GNU libc with the calloc function where in "special" circumstances, it would return an allocation that had not been zeroed. Nice.
  6. One of my all time good ones at Lycos was when I re-implemented ctime. I wanted to have the timezone offset in minutes and I was sick of the #ifdefs for the operating systems that didn't support the reentrant ctime_r function. In any case, in writing it, I left off the "Nov" in my month array. Doh! Unfortunately, I wrote the routine in April 1999 so it took a couple of months to find it and by that time, it had propagated into a lot of systems. What was amusing was that my search engine didn't have any year 2000 issues but it did have a December 1999 bug. Needless to say, my unit test program is now much more robust.
  7. Chris, one of my guys at Lycos, was having problems with my Debug Malloc library. He was trying to debug our modular spider which uses shared libraries more than any of us had before. We tracking in the debugger dmalloc handing out a heap address to the module and then tracked it being freed and dmalloc claiming that it knew nothing about the address -- that it was completely out of range.

    Turns out that because we had, improperly, compiled the modules with dmalloc and the spider which loaded the modules, they each had a separate copy of dmalloc which were completely unaware of each other. It was very strange.

  8. The one that happened today, which generated this page, is that one my guys at Lycos was having a problem with the GNU Libc (ring ring) regex library. Lewis was trying to run the same exact binary twice at the same time which we do all of the time and shouldn't be a problem. This time, however, the 1st binary would compile the regular expression "^[5-?]" and it would work. The 2nd binary would compile the same regex and it would fail on the compile. "^[5-9]" would work, "^[5-9:-?]" worked, "^[5-:]" didn't, etc..

    Turns out, as far as we can tell right now, that there is a bug in the GNU Libc regex library. God knows what it is doing to cause this but some web searches have turned up similar issues with PHP, perl, and other systems.

  9. Not a software bug, but a bizarre occurrence happened to me one time. I checked out some source code that I hadn't touched in a while and compiled it. It generated an error which was strange, given the program in question and the last time I touched it. Even more strange was the fact that a variable name had been capitalized when it was used -- something that I would never do.

    Since I knew that the ASCII character set allowed a single bit to promote a lowercase character to an uppercase one, and given the fact that my system had panicked a couple of times recently, I decided to immediately check the memory on the box. I used the excellent Memtest86 memory checker and after 20 minutes it found one of the bits in one of my memory chips was wired high -- always returning 1 even if a 0 bit was stored. I've never seen this before or since. Wild!

  10. Not a software bug, per se, but a bad choice of interface terminology. I started my own software company with a business partner in a previous life. We initially had the goal of producing customer video store rental terminals where someone could login, establish a profile, see which of their wish list tapes were available, find more-like-this tapes, surf by author, etc.. Netflix is doing this and more online quite successfully these days.

    Although we set out to write video rental terminals, we ended up writing nursing home software instead (don't ask). We wrote a nice little system running on Unix (Everex Unix and pre 1.0 BSD/OS) with a multiple text terminal interface (this was before X windows), using my own thread library, virtual keyboard, curses replacement, windows and menu interface, and a database system -- all of which I and my guys wrote. It was pretty cool although the DB needed some major work and was relatively simplistic. So our medical record system for nursing homes helped them maintain records on their patients. Each of the patient records had a master status menu which initially read something like: Alive, Dead, Transfer, or Disabled. Disabled in the computer sense however, just as a feature had been disabled, or a configuration option had been disabled. Unfortunately, disabled to nurses meant someone had a disability. Oops.

    After this had been explained to us, we released the next big version where we changed to the word "Invalid". Invalid in the computer sense and once again stumbled into a term which meant something different to our clients. Sigh. Obvious to us in retrospect but not beforehand. I think we finally chose "Not Valid" after much discussion. The company was very much on the bleeding edge and made all of the typical errors: no specifications, few realistic schedules, many word of mouth agreements, moving target projects, bad communication and organization, terrible financial or other business records, etc.. But we did deliver a Unix based nursing home medical records system to 10 or so homes in Ohio which was well received. Then again, maybe all they really liked was the "Joke of the Day" which popped up when they logged in.

Free Spam Protection   Eggnog Recipe   Android ORM   Simple Java Magic   JMX using HTTP   OAuth 2.0 Simple Example   Great Eggnog Recipe