Why Zunes broke down on Dec 31st?

This is why all zunes went blank on Dec 31st. Can you spot the simple mistake?

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

// Determine whether it is a leap year
month_tab = (UINT8 *)((IsLeapYear(year))? monthtable_leap : monthtable);

for (month=0; month<12; month++)
{
if (days < = month_tab[month])
break;
days -= month_tab[month];
}

month += 1;

lpTime->wDay = days;
lpTime->wDayOfWeek = dayofweek;
lpTime->wMonth = month;
lpTime->wYear = year;

return TRUE;
}

3 Comments:

  1. Consider the case when its the final day of a leap year ie days=366. It will execute the IsLeapYear(year) section, however it will not execute the if (days > 366) clause and as a result, the value of days will not be altered. It will just be in an infinite loop at that point.

  2. Absolutely Correct.

Leave a Reply