• Worf (unregistered) in reply to jimlangrunner
    jimlangrunner:
    Had to run that through my "code review module" a couple of times. (Hey - it's New Year's Day.) "1" and "60" work just fine. What could go wrong? Then I plugged in "365" and saw day 0 pop out. Ouch. I feel for the code review team that missed that.

    Considering the Zune OS is really Windows CE, there's no excuse for such code at all. Especially since Windows CE exposes a full set of date-related computation functions for you. I've worked on RTC drivers, and the way to get things set up is to take the current SYSTEMTIME and either program it into the hardware directly (a lot of hardware chips do BCD day/date/month/year/hour/minute/second calculations internally), or if it's lamer and does a seconds-since-some-epoch, you convert the SYSTEMTIME to a FILETIME (64 bit monotonically increasing humber since Jan 1904 - 100ns increment interval), compute the difference to your chosen epoch FILETIME, then convert from that to seconds (a nice round number... 10 million I believe), and boom, you're done.

    The only reason in the world to test a date would be to ensure that it's within bounds, and it's just checking that day of week is 0-6 (or 1-7), the months have proper days (only reason to need a leap-year test, and that code is around), and the month is between 0-11 (or 1-12) before starting the computation. Anytime I have to start writing code with dates, there's no reason to not use OS provided functions. Small embedded systems probably don't have date functions, but then again, maybe that's an indication to try to rewrite your code to either not use dates at all, or push the date stuff to a more powerful processor with an OS and date functions.

  • (cs) in reply to configurator
    configurator:
    So the zune bug would cause an infinite loop when days is 366 on a leap year?

    And I thought Apple's address was 1 Infinite Loop :-D

    You'd really think a company would run some unit tests on their firmware before shipping a gazillion devices (they wish), but no...

  • ikdind (unregistered)

    Ugh... bad memories of Zune2k9, which I just had to go through. When will we learn that leap years happen every 4 years and have 366 days?

  • ikdind (unregistered) in reply to Alexis de Torquemada

    To be fair, the original firmware worked just fine and a lot of people fixed their Zunes by disconnecting the batteries and forcing it to reset to its original firmware. It was one of the firmware updates after they had shipped tens of units that caused the infinite loop.

  • (cs) in reply to ikdind
    ikdind:
    Ugh... bad memories of Zune2k9, which I just had to go through. When will we learn that leap years happen every 4 years and have 366 days?
    Leap years happen every 4 years if you have the Y2100 bug. Hint: http://en.wikipedia.org/wiki/Leap_year#Algorithm
  • (cs) in reply to Lupus.Umbrae
    Lupus.Umbrae:
    So, who the hell is/was Molly Ringwald?

    She is an actress and was, back in the 80s, a member of the "Brat Pack" along with Emilio Estevez, Anthony Michael Hall, Andrew McCarthy, Judd Nelson, Demi Moore, Ally Sheedy and some others I'm probably forgetting.

    She's the ginger haired one from "The Breakfast Club". She was also in "Not Another Teen Movie" as a cameo, the check-in attendant at the end, iirc.

  • Dirk Diggler (unregistered) in reply to ikdind
    ikdind:
    Ugh... bad memories of Zune2k9, which I just had to go through. When will we learn that leap years happen every 4 years and have 366 days?
    Actually, they don't happen every 4 years.
  • rast (unregistered) in reply to hikari
    hikari:
    She's the ginger haired one from "The Breakfast Club".
    [image]
  • (cs)

    If I recall, I had trouble getting my Wang back up in 1984!

    If only I knew there was someone else to blame.

  • Dirk Diggler (unregistered) in reply to ParkinT
    ParkinT:
    If I recall, I had trouble getting my Wang back up in 1984!

    If only I knew there was someone else to blame.

    In 1984 I had no problems with my Wang.

  • InsanityCubed (unregistered) in reply to jimlangrunner
    jimlangrunner:
    Kender:
    Here's the Zune bug:
    BOOL ConvertDays(UINT32 days, SYSTEMTIME* lpTime)
    {
        int dayofweek, month, year;
        UINT8 *month_tab;
    
    //Calculate current day of the week
    dayofweek = GetDayOfWeek(days);
    
    year = ORIGINYEAR;
    
    while (days > 365)
    {
        if (IsLeapYear(year))
        {
            if (days > 366)
            {
                days -= 366;
                year += 1;
            }
        }
        else
        {
            days -= 365;
            year += 1;
        }
    }
    

    http://pastie.org/349916

    Had to run that through my "code review module" a couple of times. (Hey - it's New Year's Day.) "1" and "60" work just fine. What could go wrong? Then I plugged in "365" and saw day 0 pop out. Ouch. I feel for the code review team that missed that.

    I think you need to double check your "code review module"

    while (days > 365) should return false and day 365 will return. Now try day 366 on a leap year and you will see a real problem.

  • LordVashtal (unregistered)

    Wang VS, eh? Sounds like cockfighting to me...

  • (cs)

    You can't beat a Wang for a good date.

  • airdrummer (unregistered) in reply to Dirk Diggler

    i'd just started with a new co., and the proj. was a cobol fin.mgt system on a wang...the file sys. had 1 dir. level, but the dynamic linking made programming in that limited space easy:-)

  • (cs) in reply to sluq
    sluq:
    "grinded"?
    Indeed, I remember making a similar comment the last time it came up. Which I could've sworn wasn't 25 years or a year and a half ago.
  • Grammar, please (unregistered)

    Using "grinded" rather than "ground" makes it sound like you should break the banjos out.

  • Some dude (unregistered) in reply to Lupus.Umbrae
    Lupus.Umbrae:
    There were three big rages back in the 1980’s: Rubik’s cubes, Molly Ringwald, and Wangs. While I’m sure you are all familiar with those(...)

    So, who the hell is/was Molly Ringwald?

    My thoughts were more like: What the hell is a Wang?

  • Omega (unregistered) in reply to Some dude
    Some dude:
    Lupus.Umbrae:
    There were three big rages back in the 1980’s: Rubik’s cubes, Molly Ringwald, and Wangs. While I’m sure you are all familiar with those(...)

    So, who the hell is/was Molly Ringwald?

    My thoughts were more like: What the hell is a Wang?

    If you don't know what a Wang is, are you sure you're a dude? Where's your dignissim?

Leave a comment on “Classic WTF: The Bug That Shut Down Computers World-Wide”

Log In or post as a guest

Replying to comment #:

« Return to Article