Cause of Zune Leap Year Bug

Someone on Zuneboards has found the actual snippet of code that’s causing the recent Zune crashes:

year = ORIGINYEAR; /* = 1980 */

while (days > 365)
{
    if (IsLeapYear(year))
    {
        if (days > 366)
        {
            days -= 366;
            year += 1;
        }
    }
    else
    {
        days -= 365;
        year += 1;
    }
}

The Zune stores the current date by keeping a track of the number of days since ‘ORIGINYEAR’. The loop works out the current year by subtracting 365 or 366 from the days counter and adding one to ORIGINYEAR.

The problem is with the conditional if (days > 366), which means if the current year is a leap year, the loop will never finish as days is always 366 and will never be subtracted. What it’s meant to do is if (days >= 366), although with the conditional above of if (IsLeapYear(year)) it’s not necessary at all.

This means that unless Microsoft fix this bug, it will recur at the last day of every leap year.

css.php