Land Mine

A LandMine is a bug that results from code that works properly until you touch it. The canonical examples come from compiler changes. For instance, old C compilers used to only pay attention to the first eight or so characters of an identifier. Subsequent characters in identifiers were allowed, but ignored. This created ample opportunity for a class of LandMines - identifiers that were mis-spelled in the portion unnoticed by the old compiler.

This code sat idle and unnoticed - it had been compiled and everything worked fine. Three or four years later (after several "uneventful" compiler upgrades), somebody does a seemingly innocuous change that causes the module to be recompiled (by the new version of the compiler, now paying attention to the entire identifier). Suddenly - if you're lucky - the compiler complains. This is the classic LandMine.

Variants include development shops that allow hand "tuning" of compiler-generated executables. Yes, Virginia, sometimes programmers will actually edit a binary, so that it "works" (sometimes in an attempt to "fix" compiler "errors").


I came very close to doing that once. However, I read the documentation first, and found the problem could be avoided by turning off integer overflow checks: right shift 8 on a sixteen bit variable should fit in an eight bit variable, right? Wrong! The sign extension killed it. Turning off integer overflow checks shut up the runtime system resulted in the code doing what it was supposed to do. The thing is, that code had managed to not fire on any testing, and only when hand-testing the next feature based on it was it inadvertently triggered from the GUI. If it hadn't been triggered, nothing would have stopped it from entering production like that. - JoshuaHudson

Isn't masking to the lower eight bits after shifting closer to the RightThing in that context? Maybe if it's an inner loop turning off overflow checking is sensible for performance, but I prefer the ShipWithAssertionsOn effect that integer overflow checking provides. -- JeffreyHantin

Masking the bits afterwards worked when pulling the negative number apart but not when putting it back together again.


CategoryCodingIssues CategoryBug


EditText of this page (last edited November 11, 2010) or FindPage with title or text search

Meatball