Microsoft Zune

The code that caused certain Zunes to freeze is here. And the offending logic:

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;
}
}

So what happened to all of those poor Zunes? The code looks at the number of days that has elapsed since a predefined ORIGINYEAR of January 1, 1980. Then it keeps on subtracting 365 days (or 366, in the case of a leap year) from the total number of days, adding one to the year value, until it can no longer do so. What should result is the correct year.

However, if you push December 31 through on a leap year then there are 366 days. Which is greater than 365 days but not greater than 366 days.

The code goes something like this. Are the number of days greater than 366? Yes. Is it a leap year? Yes. Are the days greater than 366? No. And so nothing happens. The code loops back and continues to repeat FOREVER.

Result? Frozen Zune.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.