Article 691FW CodeSOD: Unequal Code

CodeSOD: Unequal Code

by
Remy Porter
from The Daily WTF on (#691FW)

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?

otter-icon.png [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments