Wonder why Microsoft Zune fail on New Year leap year? It’s because of a Freescale date routine!

[code lang=“c”]year = ORIGINYEAR; /* = 1980 */

while (days > 365)

{

if (IsLeapYear(year))

{

if (days > 366)

{

days -= 366;

year += 1;

}

}

else

{

days -= 365;

year += 1;

}

}[/code]

Under normal circumstances, this works just fine. The function keeps subtracting either 365 or 366 until it gets down to less than a year’s worth of days, which it then turns into the month and day of month. Thing is, in the case of the last day of a leap year, it keeps going until it hits 366. Thanks to the if (days > 366), it stops subtracting anything if the loop happens to be on a leap year. But 366 is too large to break out of the main loop, meaning that the Zune keeps looping forever and doesn’t do anything else. (Source: ZuneBoard)

User “itsnotabigtruck” of ZuneBoard forum made that interesting find.

comments powered by Disqus