Simple bug froze up MS Zune mp3 players

来源: nuxrl 2009-01-04 17:48:58 [] [博客] [旧帖] [给我悄悄话] 本文已被阅读: 次 (1931 bytes)
On 12/31/2008, MS Zune mp3 players froze up globally. No response to any request, even after reset/reboot. It turns out that such a massive disaster is caused by a simple bug in the rtc.c (real-time clock) module. Here below is the buggy code.

#define ORIGINYEAR 1980 // the begin year
...
...

//------------------------------------------------------------------------------
//
// Function: ConvertDays
//
// Local helper function that split total days since Jan 1, ORIGINYEAR into
// year, month and day
//
// Parameters:
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//------------------------------------------------------------------------------
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;
}

Year 2008 is a leap year, it has 366 days. Whoops! It's stuck (days = 366) in the while loop FOREVER.

所有跟帖: 

The fix is to wait for 1 day -rx300- 给 rx300 发送悄悄话 (754 bytes) () 01/05/2009 postreply 21:01:34

请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”