I’m curious if anyone has any real stories of a missing semicolon causing a problem in their running software.
I’m curious if anyone has any real stories of a missing semicolon causing a problem in their running software.
doSomething(),
DEBUG_MACRO("Print some text");
And mistakenly put a comma instead of semicolon at the end of the first row. I didn't notice the typo, because it compiled and ran just fine: the thing on the left of the comma and the thing on the right were both expressions, which is valid with the C "comma operator". But, on some build settings, "DEBUG_MACRO" became an if statement (it expanded to something like "if (debuggingIsOn) ..."), which is not an expression and thus not valid with the comma operator.Lesson learned: always build and test all build configurations continuously during development. Don't leave it to the last minute.
It turned out, the original author had written it as a 2 digit number for consistency, like this: 03
In C, a leading 0 indicates the number is octal, so 07 is a valid number, but 08 is not.
I was inexperienced at reading compilerese (and source control and diffing were not commonplace at that time) and it took me a good day to extricate myself from my bewilderment.
I'm still mildly amused that such a small change to a more-or-less working codebase produced such generous output...
"The most expensive hyphen in history"
Setting up a GPO to push Microsoft updates to clients in an AD domain, I spent ~8 hours debugging why the clients couldn't connect to the WSUS server. It turned out that there was trailing whitespace in the server URL text field that was getting parsed.
As a side note, this type of story IMO doesn't actually play that well in interview situations.
Far too many instances of copy/pastes including those bloody things.
AKA
if ((unusual condition) || (something other condition)); {
do_something();
}
will buy a nice fat warning the same as using "=" in a control statement. Bonus if the semi-colon comes from a macro so its not actually visible in the code sequence. const foo = [['bar'], ['baz']];
[0, 1].forEach(x => x*x);
foo will be the array, as expected. But forget the semicolon and foo is assigned the return of forEach, a.k.a undefined. The syntax is valid, but is not evaluated to what you would naively expect. if (foo);
fooBar();
Fortunately I've only wasted a couple of hours on that one.So, not a missing semicolon, but pretty close . . .