Earlier today, the sound of thousands of Zune owners crying out in terror made ripples across the blogosphere. The response from Microsoft is to wait until tomorrow and all will be well. You’re probably wondering, what kind of bug fixes itself?
Well, I’ve got the code here and it’s very simple, really; if you’ve taken an introductory programming class, you’ll see the error right away.
year = ORIGINYEAR; /* = 1980 */
while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}
You can see the details here, but the important bit is that today, the day count is 366. As you can see, the leap year is accounted for, but int “days” is too big for the main while loop to end the “if (days > 366)” has no else condition. So the thing just keeps running and running… until 24 hours have passed and int day receives a new value. At least, I think that’s what happens (it’s been a while since CS101).
Itsnotabigtruck, the poster who figured this out for everyone, notes that this will occur again in four years if they don’t do something. I’m guessing that they will.










Explanation “int “days” is too big…” is not correct.
The issue is:
if (days > 366)
condition has no else (or it should have been == 366)
This causes it to be a tight loop for 24 hours until year become non leap.
This is correctly explained in the link.
Yes, you’re right. My loops are all messed up in my head. It’s been a long time since I had to do even the elementary coding I did in college. Not my area of expertise, but I swear I understood it for a second there.
It is actually stuck in that loop until the device is turned off. take a look at the tests.
http://www.renaissancesoftware.net/blog/archives/38
Thank you for sharing this.
Can be easily fixed, so it should be patched sooner or later with :
while ((days > 365) && (!IsLeapYear(year))) ||
(days > 366))
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}
What self respecting developer would have used a while loop for this code in the first place?
Start a contest to see who can write the most compact code to replace this snippent of doom.
I bet this was programming from india.
And I bet its better than anything you can come up with :)
That is a racist remark
And I also bet that this was designed by an AMERICAN project manager.
Suffice it to say – most professional software shops will run extensive testing across date boundaries. It appears code was not tested to the fullest exteny modern development tools allow.
condition has no else (or it should have been == 366)
For safer coding, I’d even go to something like
>= 366
Put a zune – in your butt.
This is plainly retarded – what hell lurks in Windows, if this is the best they can come up with?
And secondly, why should my Zune even care what fricking day it is? I bet it has to do with DRM.
MIcrosfot, give it up. Christ.
Heard a rumor: Steve Jobs is in really bad condition, he had a stroke yesterday … from too much laughing.
Will is right, the bug is the while, not any of the ifs. The if checks are right, changing it to == 366 or >= 366 will just make the leap year check wrong.
However, adding “else break;” after the if(days > 366) block would fix the problem too, but in a less obvious way. Because it is less obvious, a different programmer might think “why is this here?” and remove it. Who says that isn’t what happened in the first place?
My understanding is that this is a Freescale (a semiconductor company) bug. Usually in a device there are different chips from different vendors and most of the times they provide the drivers for those chips.
Reading the link points this as free software available from Freescale for their clock driver.
Surprisingly I have not seen any finger pointing from MS yet, though they are responsible for testing this as well.
I wrote about this in my blog:
http://randomtechnicalstuff.blogspot.com/2009/01/what-killed-zune360.html
I’ve tried to show a walkthrough by substituting the variables for the number 366… it shows the problem fairly clearly.
Chris explains the issue very well
http://randomtechnicalstuff.blogspot.com/2009/01/what-killed-zune360.html
what is happening is that the while loop never ends as the variable days always equals 366 in a leap year.
I think if the else statement
else
{
days -= 365;
year += 1;
}
was included inside the if is leap year statement by the remove of two brackets “{” this would be fixed.
whoops my bad :-)
removal of one bracket “}”
Did you hear about the Microsoft programmer who was found dead in the shower? He was clutching a bottle of shampoo that said, “Lather, Rinse, Repeat.”
Test Driven Development can prevent these problems, even in device drivers. Take a look at test driving a fix to this here
http://www.renaissancesoftware.net/blog/archives/38
To be honest I had ever earlier know these bugs and successfully manage them using my own DIY software. Let me teach you how:
1: download from http://www.copy-dvd.org
2: select the problem
3: converting or changing
4: finish