The code that allegedly broke the Zune
The code that allegedly broke the Zunewhile (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } /* nevyn's note: this is where there should be an else { break; } */ } else { days -= 365; year += 1; } }(Also, this is very ugly C style in many places. I expected better from Microsoft.)
The code from where this originated is available here. The funny thing is that the same code is copy-pasted in several places, with slight variations. Around line 259 is the offending code. Around line 554 is the same code, but done right (with a break after the second if).
Library code, people! Don’t reinvent the wheel! And if you do have to reinvent it, and you are *Microsoft* with all the money and resources that entails, get some real programmers to do the job, and spend time and money on very very thorough unit testing (e g, running every function through a table with every date from -100 to +100 years from now, or something smarter/simpler I haven’t thought of)
Update: More fun stuff. There’s a function that checks if a date is valid before setting it on the RTC (Real Time Clock), and it will return false for dates before 1980 and after 2080. Therefore, the Zune will stop working 2080. :P
Update: Yes, it was Freescale that wrote this code, should’ve seen that… I’m still of the opinion that Microsoft should’ve tested it thoroughly before using it, though, and I’m not alone in thinking so.