My funniest bug ever: the Windows 2 resource compiler

Over on Eric Hellman’s blog, I was reading a recent entry entitled My Funnest Bugfix Ever: the Double Relative Redirect, and it reminded me of a war story of my own. Others might be amused; I’ll be interested in who can guess, how soon, what was going on.

It was 1990 or possibly 1991, and I was working on an Application for Windows 2 – which at that time was a rather exotic extra that a few adventurous people were running on top of their MS-DOS systems. There was no graphical development environment in those days: you’d compile your program using the command-line C compiler cl, and compile your resources (dialogue boxes, menus and suchlike) using the command-line resource compiler, rc.

Although this was a bit laborious, it did work, and I was able to make some progress working on and off on this project through June and July. Then the first time I tried to rebuild the resources in August, it failed to build with a spectacularly uninformative error message which sadly I no longer have a copy of: I do remember that it said “bad octal digit” but gave no indication of where in the file the problem was. In fact, come to think of it, that may very well have been the entire text of the error.

Anyone have an idea what was happening yet?

OK, next hint: we were using SCCS (“Source Code Control System”), an early and primitive version-control system that was the forerunner of tools like CVS and git. Now can you guess what was happening?

OK, last hint: I would have run into this problem before August if I’d been working full-time on the Windows project, rather than switching between this and other work. Specifically, the problem would have manifested in both June and July, but only on the 8th and 9th of the month.

Got it now?

It was a bug in the resource compiler. For some reason, its lexical analyser worked its way through comments, identifying (and discarding) lexical tokens within the comments rather than just identifying and discarding the entire comment. We were using a header-comment that contained the magic sequence %D%, which SCCS expands into the current date – this is nice because it means the first line of your file includes a note of when it was modified (and by whom, and what the file is called, depending on what other magic sequences you include).

The date was being rendered with the month in zero-padded form – so when I checked the file in on the first of August and tried to compile it, the header said something like:

st.rc, version 1.23, last modified 01/08/1990

And the resource compiler, seeing the sequence “08” in the middle of that comment, decided that the leading zero meant an octal integer constant, and then rejected it because 8 is not a valid octal digit.

Har har. How we laughed.

Lessons for today? Although the specific tool that did this is long gone, the obvious moral is that whatever else your development tools do, they should emit clear, specific error messages. It’s bad enough that rc lexed its way through my comment, but if had at least had the decency to say “bad octal constant ‘08’ at st.rc, line 1” then I wouldn’t have had to waste half a day scratching my head.