Zune Kaboom
In the epic-fail department, people sporting the Microsoft Zune on December 31st were dismayed to find their portable entertainment system had gone belly up. Apparently the little-iPod’s-that-couldn’t spontaneously rebooted themselves, locked up, took their collective balls and went home. No magical hold down five keys and count to 100 did a bit of good.
Not being a Zune owner, I found this pretty entertaining, but not worth a blog post. That is until somebody, somehow, posted the offending code (hopefully MS legal won’t take the code down by the time you read this). It is too good not to share. The problem comes in this little loop at ~line 260.
while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } } else { days -= 365; year += 1; } }
You don’t have to be a C programmer to spot the problem. Last year was leap year, which means we got 366 days instead of the usual 365. Basically, you hit the routine because there are more than 365 days, but the if (days > 366) condition is never true, so that loop never fires, so the surrounding while loop never terminates.
Oops.
Microsoft’s fix was simple - wait until tomorrow. When Jaunary 1 hit, the loop was bypassed completely, so the Zunes started working again. Presumably this will be fixed in a firmware upgrade*, although they may just assume nobody is going to be using the Zune in 4 years anyway.
*Maybe they’ll clean up the code a bit as well. When I saw those goto statements I went blind for nearly 5 seconds.