More of a programming nerd than is strictly healthy. See also {nevyn.nu, thirdcog.eu, twitter}

Projects

Overooped

Reblogged from Marco's stuff

The code that allegedly broke the Zune

marco < jstn:

while (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.

  1. snippet reblogged this from jstn
  2. allincircles reblogged this from marco
  3. chancegarcia reblogged this from trotzke
  4. lanceturner reblogged this from jstn
  5. trotzke reblogged this from marco
  6. romansang-marino reblogged this from ratatat
  7. ratatat reblogged this from marco
  8. parx reblogged this from poortaste
  9. perkyblackchick reblogged this from ledenes
  10. microblog reblogged this from marco
  11. aladuh reblogged this from marco
  12. darknessfalls reblogged this from jstn
  13. ronworkman reblogged this from jstn
  14. nevyn reblogged this from marco and added:
    The code from where...originated is available here. The funny thing is that the same code...
  15. uninformat reblogged this from marco
  16. benglert reblogged this from midoriw and added:
    Also, who hard-codes magic numbers like that? So many things wrong with this picture.
  17. midoriw reblogged this from marco
  18. shabdar reblogged this from marco and added:
    “I expect” is...diffrent story! Microsoft...like a hot...
  19. marco reblogged this from jstn and added:
    Out of curiosity, why was this being rewritten by Freescale or Microsoft at all? This has been a solved problem for a...
  20. inothernews reblogged this from ledenes
  21. ledenes reblogged this from ryanjpointer
  22. ryanjpointer reblogged this from jstn
  23. poortaste reblogged this from jstn
  24. sparo reblogged this from jstn
  25. jstn posted this