CodeSOD: Unequal Code
Ryan's co-worker caught a high priority ticket- certain features of their dashboard app were crashing when anyone tried to access them. It didn't take long to figure out that there was a stack overflow, and that some recursive function was blowing out the stack.
It took a little longer to find the recursive function in their C# code base:
public static bool operator !=(MatrixObjectKey a, object b){ if (a != null) return (a.Equals(b) == false); else return false;}
This is an overload for the != operator, which compares a MatrixObjectKey against any arbitrary object. "Any arbitrary object" would include nulls, so a != null invokes this function.
This, by the way, is why operator overloading is often considered a code smell- you can be surprised by the behavior of seemingly innocuous code. But the bigger smell is how this code got released- somehow this never got caught by any level of testing?
They were testing, right? Right?
[Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!