Obvious in retrospect, but took me a minute to catch on to what’s going on here:
public void DoStuff(byte maximum)
{
for(byte i = 1; i <= maximum; i++)
{
// whatever
}
}
This works like a trooper until someone passes in a byte.MaxValue in a unit test and i becomes 0 after reaching maximum and getting incremented again.
Cory Fowler
/ September 2, 2010Could you imagine finding that as a defect down the road…. Thank God for Unit Tests!
Joshua Kehn
/ October 7, 2010Interesting bug, glad it got caught. Looks inconspicuous enough.
Jduv
/ January 15, 2011This is where the checked keyword can save your bacon.