The Exact Cause of the Zune Meltdown
An anonymous reader writes "The Zune 30 failure became national news when it happened just three days ago. The source code for the bad driver leaked soon after, and now, someone has come up with a very detailed explanation for where the code was bad as well as a number of solutions to deal with it. From a coding/QA standpoint, one has to wonder how this bug was missed if the quality assurance team wasn't slacking off. Worse yet: this bug affects every Windows CE device carrying this driver."
And who uses Windows CE?
It wasn't a bug! It was an unexpected feature!
Microsoft is taking a stance against teenagers blowing their ears out with loud music.
Just before anybody claims to have a foolproof solution to leap years, make sure you test against the year 2100. It's a multiple of four, but also a multiple of 100 that's not a multiple of 400... and therefore NOT a leap year.
And you are a programmer, I would highly recommend the book Deep C Secrets. It's partly practical and partly culture. It covers some well (and lesser) known bugs that while very small and "stupid" had very real consequences.
Methinks it was the same f*cked up code monkey that wrote this summary!
"From a coding/QA standpoint, one has to wonder how this bug was missed if the quality assurance team wasn't slacking off."
I can't remember the last time a QA department was asked to test date functions... but then again, I can't remember the last time anyone wrote their own Leap Year calendaring calculator from scratch.
I'm sure there are a hundred reasons to do it (licensing being one of them) but really, when was the last time you didn't just import calendaring from another library and call it a day?
Please clarify to me if this is something at the hardware driver level: I honestly don't know. If this were me, my own bosses wouldn't ask "Why didn't QA catch this", as much as "why are you wasting time writing your own calendar code? And then why didn't you flag it as functionality that needed to be tested?"
It's an open source driver from Freescale.
You know there's a problem when Digg covers this technology news before Slashdot.
Yep, but it deserves to be covered so that everybody hears it. It's not just a laugh at Microsoft story, but also a lesson to aspiring programmers to watch there step when it comes to timekeeping. Gotta get a mention to the people who look at /. at work, gotta get a mention to the people who visit weeknights, gotta mention it for the weekend crowd.
My first reaction to this is wondering why anyone would decide to write their own date/time code. I would expect there to be several good options for open source date/time code that is mature and proven to work right.
From a coding/QA standpoint, one has to wonder how this bug was missed if the quality assurance team wasn't slacking off.
MSFT's QA team hasn't been slacking off. They haven't slacked on since about the mid 90s.
This kind of bug is where TDD shines. If you don't write any code unless you have a test that forces you to, it's very hard to produce this bug type.
(TDD = Test Driven Development)
For example I had some code I developed on Windows CE 4.2 .NET which kept on hanging on calling the FindWindow() fuction call.
Turns out that trying to find a window by class name will hang (this version of) CE every time, even though you would have thought its a very much used function call and would be caught by CE.
So no I'm not surprised at all that this bug got through.
Looking at that code, it never had effective code review or Q/A. If I was the manager responsible I would be looking up those who signed off on the code in the last review. I didn't spot one, but 4 issues in that code and would not doubt more exist. Second off, there are much simpler ways of doing this in the C libraries, and simplicty has value.
But the design, I suspect is very flawed. Why not use asctime() and rely on it's more proven calculations of leap year and the like via the OS libraries?
And when you see something like this, you know someones brain was in the off position:
556 day -= 366;
557 year += 1;
Lines 122, 521, 690, 710, and 748 scare me; gotos in C code...
Both the original code and the various corrections in the article don't catch what the algorithm is supposed to do, and therefore create code that is too complicated.
The essence of the algorithm is this: We start with number of days since 1/Jan/1980, with the first day having the number one. We want to end up with the correct year, with a day number relative to the first day of that year, with the first day again having the number one. So we set year = 1980. And as long as day is greater than the number of days in that year, we can't have the right value yet, so we change day and year accordingly. This produces a very simple loop:
for (;;) {
int daysInYear = IsLeapYear (year) ? 366 : 365;
if (day = daysInYear) break;
day -= daysInYear; year += 1;
}
This is what Knuth called an "N + 1/2" loop: A loop pattern where a more or less substantial bit of code has to be executed at the beginning of the loop before we can decide whether the loop needs exiting or continuing. By following the "N+1/2 loop" pattern we avoid repeating the same code (with possible small changes) completely. And that exactly was the problem here: The same code was used twice but slightly differently (one set number of days = 365, the other made it dependent on whether the year was a leap year or not). The solutions given in the article all contain repeated code; either two loop exits, or a duplicated calculation of the number of days in a year.
Software for time computations should use the *Modified Julian Day* [1] which provides a continuous time measure. You can find implementations of the conversion algorithms in astronomy software (including even the Gregorian calendar reform for those really old music files).
[1] http://en.wikipedia.org/wiki/Julian_day
[2] http://en.wikipedia.org/wiki/Gregorian_calendar
integer function f_isleap(year) :: Return 0 if a year is NOT leap year and a 1 otherwise. .or. .and.
IMPLICIT NONE
c
c Purpose
c
c Description: Every fourth year is a leap year. c But NOT when divisible
c by 100, except if the year is divisible by 400.
c
integer Year
if((MOD(Year,400).eq.0)
% ((MOD(Year,4).eq.0)
(MOD(Year,100).ne.0))) then
f_isleap=1
else
f_isleap=0
endif
return
end
But of course FORTRAN is not fancy enough for super cool C# coders.
Comments in the last zune slashdot story (yesterday?) were just as detailed as this "story". Maybe slashdot editors should read their own site. Or maybe I should start submitting all +5 comments for their own story.
Do you even lift?
These aren't the 'roids you're looking for.
Exactly, just goes to show the dangers in not QA'ing the whole codebase including supplied drivers. You can't trust your own code so you QA it, why should you trust your partner's code.
This code is actually from the Windows CE OAL (OEM Abstraction Layer), part of the code that reads the current time from the RTC. As such, the implementation is hardware-dependent, which is why there isn't a standard implementation of this function for Windows CE.
In addition, this code is in a portion of Windows CE source code provided by a device's BSP developer, not by Microsoft. In most cases, Windows CE BSP developers start with sample BSPs written by a processor's manufacturer -- in this case, Freescale -- and then improve it.
It turns out that this bug is specific to the Freescale's BSP -- sample Windows CE BSPs for other procesors don't have it -- and other Freescale devices using Windows CE will only have this issue if their developers used this code verbatim. Since sample BSPs provided by processor manufacturers are often of poor quality, many Windows CE developers typically rewrite such functions. In other words, the impact of this particular bug may be quite limited, which may be why there haven't been reports of this issue on other devices.
In this particular case, though, Microsoft (or a contractor) was the Zune's BSP developer, so they certainly should have caught this.
This is what happens when there are no serious consequences for the bad work.
They seriously need to lay off the bottom 10% (or 20?) of their workforce for the first time in company lifetime. Some people ought to be scared of bad work they do. There's no way for any company that all 100% of workforce are productive and useful.
I bet remaining workforce and end-users would thank them.
I think the exact cause can be summed up as this: It's Microsoft.
I've seen reports of the bug happening on 1 Jan, and the summary seems to say that too. But shouldn't the bug have happened on the 31 December, the 366th day of 2008?
Wow. That link is to a book from a good web site: Free eBooks.
Other free books about C and C++: Free C and C++ books
Really? I didn't see many examples of alternate solutions to this.
It's annoying, but people keep thinking of Microsoft as a mediocre computer company that is sometimes abusive. But it isn't. Microsoft is a perfect abuse company that uses computer software and hardware to deliver abuse.
Just my opinion, but I'm not the only one.
http://xkcd.com/376/
What I see here is a really convoluted piece of code to perform a really simple task. There are a lot of constants that are written as constants. If there a #define orginyear, the why not #define daysperyear and #define daysperleapyear. The first is used only once, while the rest are used twice.
In any case, the fundamental problem is not encapsulating data. This is quite a common error is code architecture. In this case, this function knows a lot of things it does not need to know. It know about leap years, number of days, and all this confuses the reader. They layout of the function already has the overhead of a fuction call, so why do we not let this overhead work for us by not returning the proxy leap year boolean, but what we actually want, which is the number of days in this year.
In this case all days per year information and leap year information is encapsulated in a single function, and the top function does not need to know about either. This, I think, is writing quality into code, and not depending on QA to catch mistakes common to novice programmers. No guarantee this will work as is, it is just psuedo code, not even checking the logic completely.
"She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
That's the mindset of most software developers and managers. And when it is done, it is done incorrectly, tacked on at the end as if you are testing a dishwasher.
QA/QC (there is no uniform definition of the two) pays off if you build it into every step of development from day one and follow through. Unit testing is a part of it (and is a great idea, it really helped me), but only a part.
Read Demming.
putting the 'B' in LGBTQ+
The whole I.T. industrial is modeling. The computing world is a model of the real world. One can not map the whole world in their computer world, that some kinds of simplification is needed.
How much detail is enough? No body ever answer that, and no one care.
Y2K is just Y2K. how long does a time representation is enough? How big should the address pointer?
Is anybody care about that? The whole industrial is based on assumption: this is enough and it turn out the actual answer is NO.
Starting from the beginning of our education, we demonistration all such unthinking simplification of the representation of the real world. And the whole industrial does not take a second through of how these simplification were causing us.
Every people write system requirement just boost their specification from time to time. No body really get those cut-off points into the specification. No efforts ever put to identification where we have made a simplification which may cause our arms or legs when time come.
The whole computing education and education should rethink this modeling issue.
from TFA:
"So what's the purpose of the while loop? To put it simply, it's designed to get the number of years from the number of days since 1980 as well as a remainder of days out of the current year."
WTF? It's supposed to a media player. Just play the media and don't worry about trying to do other crap!
... there was a case of this happening in the first generation of Zunes that were shipped.
The result was many high level management officials were fired and some of the niglet employees thoroughly raped.
SHUT UP YOU FUCKING CUNT YOUR PENIS IS SHOWING
The bug reportedly affected only fully patched and updated Zunes.... those that did not receive firmware updates were safe. In which case, how can this be a fundamental bug affecting *ALL* Zunes from production?
Looks like the bug was deliberately introduced as a firmware update. That has to be properly explained.
BTW, I haven't seen a similar explanation for the Excel 2007 '100000' bug yet.
If you keep throwing chairs, one day you'll break windows....
The proper way to do this would be with division and modulus, which gives you a nice constant time solution even if you're still using your Zune in 2108. They ought to read Calendrical Calculations by Nachum Dershowitz and Ed Reingold and learn how to do this properly.
It said something like "a bug was found in the Zune 30G from 2006, apparently some weirdos still us it." Cause, you know, 2 year old electronics is junk. Punks.
This has been a fascinating few days, even for a non-programmer like myself. A bug that is being explained in depth, rather than just explained away, buried and glossed over in some release notes.
But after reading several articles about this bug, I keep asking myself, why does a music/video player need to exactly what time it is?
The answer, appears to be the need to calculate for subscriptions and digital rights management.
Way back in the pre-Cambrian days when I actually was a decent C programmer, there was a book chalked full of algorithms. I can't remember now if it was the "Stevens" book or the "Stevenson" book. It was our bible. Our guide. The holiest book in our bookshelf. Whenever we got the yen to do some programming, we always took out the "Stevens" book and asked ourselves "What Would Stevens Do?"
In this day, is there not one such book or place where someone says "Gee, I have to write some code that will calculate the date, day of week, and year from a fixed day. I wonder if I can look up this bit of code in some reference book, and do it right the first time?"
And, then the second question: Why in the heck does the Zune care a fig about today's date? I believe there's some other device on the market that rhymes with "Shapple ShiPod" that does something similar to the Zune and yet doesn't care one whit about today's date. I won't claim that particular device is error free, but I but you a couple of doughnuts that it won't freeze up the day before a big holiday because it doesn't realize that 2008 has 366 days in it.
static int IsLeapYear( int year )
{
if ( year & 0x011 ) return 0;
switch ( year % 400 )
{
case 0:
break;
case 100:
case 200:
case 300:
return 0;
break;
default:
break;
}
return( 1 );
}
Or an undocumented feature?
First to finish is not always a good thing. Just ask your girlfriend.
Hats off to the coder who blamed on that one. You've made history!
Na that would be silly as it would require a basic understand of math.
It reminds me of a time when a teacher who was teaching Pascal explained to us that divisions where executed by repeatedly subtracting, sad but true.
There's a standard library function that performs the required functionality, see: http://linux.die.net/man/3/localtime . I think there's only one (good) excuse to do time-related calculations directly "by hand" rather than through a standard library function: It is only justified if the standard library is unavailable. But since this library, as its name suggests, is in fact _standard_ (in Windows and Unix variants alike), such situations are not that frequent...
http://www.anythingbutipod.com/archives/2009/01/zune-bug-actually-a-freescale-bug-affecting-toshiba-gigabeats-too.php
http://www.popularculturegaming.com -- my blog about the culture of videogame players
Or used hardware from another manufacturer.
"evidence of QA.. slacking off"
These comments routinely come from two groups:
1) Software Developers
2) Joe the Plumber
Or put another way: elitism or ignorance.
If a software division is letting QA "test" all on their own, that's a recipe for disaster... and it's the head of engineering at fault.
See, software testing does not occur in a vacuum, no more than developers code without a list of requirements from Sales or Marketing.
Engineering takes takes the requirements, use that to produce an agreed upon set of specifications.
QA follows the same model... they take the software specs and derive a set of effective tests.... tests which are agreed upon by Engineering, and signed off on.
When I did QA, it was mostly for startups who lacked this kind of process. The result was QA was always 2 steps behind software that continually morphed: hardware changed, or the customer changed their mind. I'm not placing the blame on any 1 group here... I come from Support, then QA, and now develop. Startups can be rough.
But at the end of the day, not documenting and agreeing on what the product and tests should be will cost you big time.. maybe 7 out of 10 times.
This kind of bug is where TDD shines.
I'm not so sure. Let's look at the timeline without TDD:
1) Microsoft writes method (say, one hour).
2) Microsoft discovers but on December 31st, 2008
3) Microsoft spends one hour fixing bug (assuming documentation and source control and test of fix)
Now lets look at that timeline with TDD:
1) Microsoft writes method (let's say one hour again)
2) Microsoft writes test for method. Test includes random dates but not December 31st, 2008. One hour.
3) Microsoft discovers but on December 31st, 2008
4) Microsoft spends one hour fixing bug (assuming documentation and source control and test of fix)
5) Microsoft updates test (one more hour to make sure all cases are caught)
Basically they spent more time on both ends, but very likely would not have prevented the error anyway. You could perhaps say the fix would take lest time since there's less testing to be done, but that's not really true as you have to verify the (also simple) changes to the test suite are correct as well...
The only advantage that TDD would have given is one more chance for the developer to think about the possible edge case after the method was written. But I would argue that with anything that fundamental more time should have gone into initial development, and TDD is the death of a thousand cuts in terms of time to write and maintain tests. Over time that gets unwieldy - I'm a believer in tests when they are meaningful and light and do not detract too much from time spent improving the code instead of tests.
Indeed I can also see where TDD could well have caused this bug. Many TDD proponents would write the test first, and then code to it - which is just the kind of thinking that lets you relax when you should be at your most vigilant, actually writing the code that does the work. I find it a lot easier to consider possibilities when I am staring at a piece of code that does some work as opposed to compiling and coding a list of potential issues into a test.
Another potential issue is that tests tend to be written by the programmer who produced the original code, and of course the natural urge is to produce tests that fit the code as is, since the general thinking is to prevent bugs from future changes. I'm a huge believer (from experience) in the value of having a QA department that does nothing but write test code and makes sure the code always passes that. It works far better than programmers managing code and really produces quality efforts. Unfortunately it has the same ossifying effect where refactoring is harder as you go along because tests must be altered along with code.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
Is it just me or does stuff like this really annoy everyone:
dayofweek = GetDayOfWeek(days);
That's basically like saying:
// See if i is greater than zero ....
if( i > 0 )
Adding unnecessary comments is worse than not commenting at all, it just dirtys up the code.
At least 15% of them will toss them away. That's 15% fewer Zunes Microsoft has to worry about and potentially 15% more in possible sales. It's basically a huge test of how much pain your customers will tolerate and an opportunity to make some money as well. But the real point of this is that Zune isn't a product. Zune itself was a big experiment in DRM to understand how customers use it. Now that Microsoft knows what they have to build into Win7 they don't need the Zune anymore and is willing to let it die.
First to finish is not always a good thing. Just ask your girlfriend.
Obligatory: you forgot that this is Slashdot....
Where are mod points when you need em?
The author of this code would have barely passed Coding 101, if they passed at all! Its crap. What's wrong with using modulus arithmetic?
Two roads diverged in a wood, and I - I took the one less travelled by. (Robert Frost, 1916)
Never use a while loop in a driver. Loops used in drivers should have a defined exit condition.
for(;;) is while(1). If you mean while(1), code while(1). Use for() when you want to enumerate something.
End of story.
Personally, I like my compiler to do my dirty work for me. Any sane compiler will optimize divisions by constant powers of two to the proper bit motion operations (as long as optimizations are enabled, of course).
They should have had unit tests that tested every day of the year from 1970 +- 70 years for that function.
Don't worry, I'll ask his girlfriend...
"Microsoft is run by morons - and greedy morons at that" doesn't anybody get here?
Richard Steven Hack - This sig is TOO GODDAMN SHORT TO DO ANYTHING USEFUL WITH! MORONS!
" Worse yet: this bug affects every Windows CE device carrying this driver. "
So who volunteers to "fix" this driver so that it implements this "feature" every day, and also "works" on all Windows platforms?
Better yet, anyone want to bet that Microsoft will do something like this (purposefully break Windows) in an update, to force people to adopt Windows7?
Kevin Smith on Prince
And yet, the simple there/their/they're thing completely escaped you, and you expect other people to keep track of math?
Yes, they're handy, but this is just fucking ridiculous.
If year = (input year here) Then February has 29 days.
Forget trying to calculate it out. I can rattle off the leap years without thinking. Make a list. Knowing how most software lasts (consumer anyways,) you only need to account for maybe 12 leap years, if your software even lasts that long to begin with.
Doing things the complicated way when a simple list and table would've sufficed is just beyond me.
Probably why I don't program, either. At least, not for any business purposes.
Still waiting on Serviscope_minor to wake up to fucking reality and realize that Jessica Price isn't going to fuck him.
I'm not so sure. Let's look at the timeline without TDD:
1) Microsoft writes method (say, one hour).
FAIL. In TDD, you first write a test. Then you run it to see if it fails. (If it doesn't, you've learned something important.)
So let's assume the bug got through. As soon as it is reported, you... what?
4) Microsoft spends one hour fixing bug (assuming documentation and source control and test of fix)
5) Microsoft updates test (one more hour to make sure all cases are caught)
FAIL. You first write a test. And it had better fail.
(None of this exempts QA from writing their own acceptance tests of the whole system, BTW. TDD is a coding technique.)
I don't write all that much code these days, but aren't there tools out there that might flag a loop with such a clear case where an infinite loop might occur? This is the kind of thing that people shouldn't have to be thinking about, if it can be automated.
Y'know, some robot should have been waving its arms around yelling, "Danger, danger, Will Robinson!"
The CB App. What's your 20?
When has Microsoft ever actually done that? Apple has released updates that DELIBERATELY bricked devices (jailbroken iphones for one), but that's ok, yet when a Microsoft device breaks due to a very obvious bug (obvious in that it's obvious it IS a bug, not obvious in that it really should have been noticed - bugs do happen in pretty much ALL software) that has a stupidly simple fix (Let it drain the battery then turn it on again), suddenly the Conspiracy theories are out in full force and they're once again branded as the most Evil Corporation on the planet? Please.
There's so much you can bash Microsoft for (legitimately), why do you feel the need to actually make shit up?
Besides, from all the reports I've read so far, Windows 7 is actually looking to be a worthy Upgrade (if you're a windows user, that is - for anyone else, your mileage may vary) and I don't just mean from Vista, I mean from XP as well.
But no, it's easier to just hate the large, monolithic, rich company than accept that sometimes shit just happens.
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
"When has Microsoft ever actually done that?"
Search for "DOS ain't done until lotus won't run." - purposefully introducing incompatibilities in the OS, just like Apple with jailbroken iPhones.
Kevin Smith on Prince
Ok, I called your bluff. I actually went and searched for it.
The VERY top link is this slashdot article which states:
"We've all heard the story of Microsoft's battle cry of "DOS ain't done till Lotus won't run". Adam Barr investigates the myth, interviewing various Microsoft and Lotus old-timers (including Mitch Kapor), and finds no basis for its legitimacy or any case of 1-2-3 actually not running. Whom to blame for Lotus Notes is not discussed."
I checked the next few links and they pretty much all pointed to the same article, namely this one. One site even described it as a "complete and utter annihilation of the myth".
I actually thought you were disagreeing with me, but now I see you were pointing out that people have been claiming the same thing for years and it was just as unfounded then as it is now. Thank you, I couldn't have said it better myself.
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
Personally, I've seen enough embedded compilers to know they don't do much more optimization than "hey look! a plus sign, lets put an ADD r01, r02 in there"...
Most embedded compilers can't tell the difference between a const pointer and a reference...
Of Code And Men
This isn't the same incident but it's the same villian: http://www.theregister.co.uk/1999/11/05/how_ms_played_the_incompatibility/
Slashdot is proof that Sturgeon's Law applies to mankind.
That's quite an interesting Article, thanks for the Link!
I would like to point out, though (For those that can't be bothered reading it all), that Microsoft never actually released the code mentioned in it. For the final release of Windows 3.1, the code was disabled and DR DOS ran fine with it.
This WAS likely due to the lawsuit, of course, but if anything it's probably the reason Microsoft takes compatibility so seriously today.
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
Ok, I'm getting sick of this claim. There is no proof that Apple has ever deliberately bricked devices. This is completely unfounded.
In fact, go back and look at the reports of iPhones breaking, and you'll see that most of them started working again with a later OS release. About the only thing that happens on upgrade with jailbroken phones these days is that they are locked again.
Check out DRM-free movies at http://www.bside.com
Interesting but wrong. While skipping the division for odd years is a worthy angle, your method will create leap years every two years except when they fall on those evenly divisible by 400.
This is not hard to test. It is probably one of the most well defined problems you could come across. Test all cases from today, until 20-50y. Not that hard if you have the test harness written...
The two cases are different though. If Lotus won't run on Dos version X+1, people will stick with Dos version X. I.e. Microsoft lose money. It's in their interests to make sure that Lotus works on each new Dos.
It would have been hard to get Windows to run properly on any Dos except MS Dos given the amount of patching Windows needed to do to Dos to work - Windows patched both the Dos code and data segments, neither of which are publically documented and both of which were very different in DR Dos. And the net result of all that work would be Microsoft would lose money because people would run Windows on DR Dos rather than MS Dos.
Still in the end they disabled the AARD code so that DR could make DR Dos compatible. From what I heard they did this by faking version checks, setting up a victim data segment that looked like MS Dos and trying to emulate the changes applications made in that victim data segment in the real DR Dos data segment. This was obviously a bit brittle, and you'd be crazy to run Windows on anything but MS Dos if you knew how much patching it needed to do.
echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
Oh wait, they do.
Some drink at the fountain of knowledge. Others just gargle.
Meh, Microsoft has a bug. News at 11. But seriously, how is this news or new or anything? Topical and current maybe, but something we haven't seen before? Be serious. Mcirosoft has the crappiest quality control in the industry. Only 1 or 2 years ago, all the programmers there were introduced to something new: full regression testing. Many long-term coders had never heard of it before. Its a way of confirming that the software works correctly for every possible case. Apparently it wasn't implemented.
So you telling me that the Zune is the only device that has ever used the Freescale code?
Hand in your geek badge and your Sherlock hat! You sir are not qualified for code review...
This should be the proper version of the quote:
I know from the actual Novell developers (I worked for Novell in 1991-92) that on multiple occasions, Microsoft modified a new Dos version between the last beta and the actual release, in such a way that Novell's Netware client drivers stopped working.
Terje
"almost all programming can be viewed as an exercise in caching"
The interesting part, at least to me, is the fact that the developers felt they had to reinvent (very badly) the algorithm to convert between day number and year-month-day, when correct & fast functions to do so have been public domain knowledge for a _very_ long time.
It is of course easy to convert from Y-M-D to daynr (year * 365 + number of leap days + days in previous months + day), particularly if you rotate the year a bit, making March 1st the first day of the year, since that removes the need to specialcase days in March or later in leap years.
Going in the opposite direction is slightly more interesting:
The best method I've found is to take advantage of the fast reverse conversion, by first guessing the approximate year, then adjust it if the reverse calculation comes out wrong.
Using this approach makes it possible to handle any legal Gregorian date up to some millions of years in the future (when 32-bit ints will overflow) and still do the conversion in about the same time as one or two integer divisions.
Terje
"almost all programming can be viewed as an exercise in caching"
who said it was okay for Apple to brick unlocked iPhones? i don't have an iPhone, but i thought it was a dick move if there ever was one.
how seriously does Microsoft take compatibility?
Obligatory xkcd reference.
8 of 13 people found this answer helpful. Did you?
I did that. That's how I learned about the web site that has numerous free books.
they placed "profit" *before* the question marks.
Table-ized A.I.
A lot more than Apple or Linux.
;).
With Linux, you can't even be sure that your hardware which was working fine on 2.4.x will continue to work fine in 2.4.y.
In contrast I believe many viruses written in the 1990s will still run fine on Windows XP in 2008
You don't know that the bug wasn't found, only that it wasn't fixed. Fixing it is the responsibility of the developers, not QA. Every software product ships with hundreds of known bugs, often against QA recommendations. The fact that -this- bug was self-correcting offers a bit of mitigation, and being Microsoft, I wouldn't be surprised if a producer signed off on it. They probably figured they'd postpone it for a patch, since leap years don't come all that often. And then later... they decided a patch wasn't worth making. That's pretty much how all bad bugs end up in RTMs without a fix.
There's a possibility that QA just didn't look for this bug, which, while bad, is also not surprising -- calendars aren't exactly a big focus when creating new software, it's assumed to be recycled code, and QA is given only so much of a budget to allocate time and resources to testing features. So even if this falls to QA not finding the bug, it would be even more true to say that the project management and finance did not allocate sufficient time or money for QA (in the worst case, if the product had been tested for 4 years prior to release, the bug would have been found by QA one way or another.)
Good to know that there won't be any elections on the 1st of January of a leap year then.
XML is like violence. If it doesn't solve the problem, use more.
How about a much simpler reason - it plain well sucks giant donkey balls.
We're talking about a device which only works with Windows, only available in a small mumber of countries (I don't give a shit about the music service - you can put music on it without a fucking music service so the need to 'roll out the service' is a bullshit excuse) and the software sucks balls.
Its a top to bottom epic failure - and its in the mold of Microsoft NEVER to learn from these failures or more correctly, learn from its rivals who are making gains. Then again, Microsoft is kinda like a mini-America, the world uses metric, the US uses imperial. The world uses 240V, and the uses 110V etc. etc.
Couldn't you just do this:
if((condition1 && condition2) || (issue1 || issue2)){
}
Most human behaviour can be explained in terms of identity.
Yeah except that the smug responses from "why not call asctime" to "how you should write the isleapyear() function" to "OMG GOTOs!!!" just tells me that nobody actually learned anything from this ordeal.
I'm willing to bet anything that what those people write will be absolute crap compared with the code we're looking at.
Don't quote me on this.
I agree. So my Zune is going to go feet up for 24 hours every 4 years, who the frakk cares. When it bricked this time, it was the first time I've ever had a problem with it, and I discovered the fix on my own before MS published it. Besides I actually like Bill Gates. You Apple fanboys can moan and piss about your iPhones bricking and it doesn't cause as much fuss as this did.
Think of how stupid the average person is, and realize half of them are stupider than that.
Apparently some devices won't work one day every 4 years.
It is less than 0.07% downtime.
I believe it is better than most of MS products.
Well, I suppose it's a typo. 0x011 should be 3. Here's a commented version:
static int IsLeapYear( int year ) {
if ( year & 3 ) return 0; // if (year not divisible by 4) return 0, no leap year
switch ( year % 400 ) { // if (year divisible by 400) return 1, leap year
case 0:
break;
case 100: // if (year divisible by 100 but not 400) return 0, no leap year
case 200:
case 300:
return 0;
default: // if (year not divisible by 100, but by 4) return 1, leap year
}
return( 1 );
}
If you register on that site don't use your real email address and your standard password.
These free book sites aren't legal and more often than not they are simply there to get peoples email addresses and default passwords they use when they register on various sites.
Here's some more examples of free book sites
http://www.freebooksclub.net/
http://1clickebooks.com/
You notice how they all have the same content?
Notice how when you actually try to download a file it takes you to a link on rapidshare that is most probably no longer valid.
See how they make you enter your email address and password? I hope you don't use the same password for everything!
These are the modern equivalent of the old scam warez sites.
I don't see how the source code being readily available for download from the site of its developer (Freescale) counts as being "leaked".
> they're once again branded as the most Evil Corporation
I wasn't aware the designation had been revoked ?
What a depressingly stupid machine.
John is that you?!
Has the boss decided what we should do if the thing has run out of storage and we can't log?
If I mod you up, it doesn't necessarily mean I agree with what you've said, sorry.
That's the problem with the net - revisionist history. Go down to your library and do some research in books in print from the early '90s, and you'll find several references to it, with citations, including one where Bill Gates says "I hope we don't get into trouble with the DoJ over this."
Kevin Smith on Prince
It was no longer in their interest to keep people on a DOS-only platform once they got serious about pushing Windows and Excel. Remember, at one time Lotus had a larger market cap than Microsoft, and there was talk of them doing an LBO of Microsoft. This scared the SHIT out of Gates and Co.
Kevin Smith on Prince
UMMM.... Maybe if 7 was free. However my copy of Windows '95 was never finished, they simply asked me to buy '98. Why can Microsoft take my money, never finish a project, and then get away with saying "buy this one now. It might work." If you pay money then the answer is no, you shouldn't have to live with "bugs".
First of all, this was a braindead stupid bug. Unbelievably poor implementation of what should have been a fairly simple thing leads to an infinite loop on special days. Just looking at the damned loop without actually tracing through every possibility reveals a infinite loop at first glance. This was mindbogglingly stupid.
Second...Apple didn't "deliberately brick" devices. Your bias here is unbelievable. What Apple did was fix a bug that was allowing people to jailbreak and that caused problems from jailbroken phones. They fixed a security flaw that caused something that took advantage of that security flaw to cease to function correctly. Now, personally I would like it if the iPhone didn't require jailbreaking to open it up, but fixing the flaw that allows people to break your security model is not "deliberatly bricking". WGA is deliberately bricking, where it arbitrarily decides that you are invalid and shuts you off. In both cases it is incorrect useage of the word "brick" since either device can be easily recovered. So...to recap. Apple fixed a security flaw that caused bad news for people jailbreaking. Microsoft told your computer to call home every day so they could arbitrarily decide if you were valid or not and then shut you off if you werent.
It is easier to hate the large monolitic rich company that uses illegal business practices, breaks the standards, and buys off the DoJ to avoid punishment (Go look at MS political contributions to either party before the trial...virtually nil...then the year they get busted...they contribute big bucks to both sides and walk away with a wrist slap). Trust me...big time criminals don't need cheerleaders like you to help them out. People like you are like the wife that geats her ass kicked and says "no, but he really loves me, he really is a good guy".
The only change I can believe in is what I find in my couch cushions.
A shorter variant:
int IsLeapYear(int year)
if ( year & 0x03 ) return 0;
if ( ! ( year % 100 ) && ( year & 0x0f ) ) return 0;
return 1;
}
Altenative:
int IsLeapYear(int year)
if ( year & 0x03 ) return 0;
if (year & 0x0f) return 1;
// if year is divisible by 100 return 0, isn't leap year
// in the case of year = 400 this stament is never reached
if ( year % 100 ) return 0;
return 1;
}
I'm the same as parent, de alternbative is broken, the good version is:
int IsLeapYear(int year)
// if year is not divisible by 4 return 0, isn't leap year
// if year is not divisible by 100 return 1, it's leap year
if ( year & 0x03 ) return 0;
// if year is divisible by 16 return 1, it's leap year
// 16 is because 16*25=400,75*4=300,8*25=200, 4*25=100 and 16=4*4
if (year & 0x0f) return 1;
// in the case of year = 400 this stament is never reached
if ( year % 100 ) return 1;
//isn't a leap year
return 0;
}
stupid of me another time is broken.
this sentence in the alternative:
if (year & 0x0f) return 1;
is in reality:
if ( ! (year & 0x0f) ) return 1;
Almost. If year is disible by 16, then (year&15) is 0, aka false. You need to negate that condition.
Then roll it all into one (with one !((!a)||b) turned into (a&&(!b)):
return ((year&3)||((year&15)&&(!(year%100))))?false:true;
or ?0:1 or ?365:366, depending on language and application. This code probably warrants a //don't touch! comment.
So MACOS X is bug free? What about any licensed version of Unix? What about...oh I don't know...just about every piece of commercial software out there? Bugs happen, it's a sad shame, but it happens and no software is ever "bug free". This is why they measure bugs not by raw number, but by number per XXX lines of code - if you can keep your average below a set number, you're doing well.
I'm sure you're happy to let Linux be a tad buggy because it's open source and thus "free", but there's quite a few licensed distros you're supposed to pay for, what about those?
You should have properly researched your choice for buying Windows 95 at the time. Maybe it wasn't the right software for you, maybe you should have bought a Mac or installed Linux, but from what you're saying, you expect a piece of software to be absolutely perfect when you pay for it, so perfect that future, better versions of the OS should never be needed, so I'm fairly sure you would be bitching and complaining now that you had to upgrade no matter what you decided to buy.
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
My bias is only apparent due to the stark contrast of what I'm saying to trolltalk, since I'm taking a direct stance against him and his stance is quite clearly biased against Microsoft, my stance is going to appear to be biased towards Microsoft, that's all.
I was only using Apple as an example of another company that has done stuff quite similar to this (Perhaps the circumstances were vastly different, but the outcome was more or less the same - inoperable devices that someone has legitimately bought and paid for), yet still Microsoft were the big bad guys. I'm not saying the bug wasn't a stupid one, I'm just saying that it WAS a bug and there was absolutely no reason to throw about the "OMG Microsoft is deliberately bricking devices! Bet they do it again to make us upgrade to Windows 7" card.
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
Ok, I admit it, I didn't sleep well last night and my internet connection is down this morning (sitting here waiting for the repairman) and I'm typing this on an agonizingly slow cell card. So my comment is probably more crabby than usual. To wit:
It occurs to me that the QA department noticed the bug the moment it happened, and very quickly provided a detailed analysis of the bug, as is customary with Microsoft products. Think about it. Consumers responded within hours (sometimes minutes) of the bug surfacing, technical blogs had detailed reports the same day, a conscientious developer leaked the code, and independent analysts had detailed technical analysis of the bug within days including suggested fixes. Microsoft's next step is to present a press release on the unpaid work of others. The system works as designed. Microsoft very cleverly gets the benefits of open source without, you know, that nasty open part.
Oliver's law of assumed responsibility: If you're seen fixing it, you will be blamed for breaking it.
It is not only easier to hate M$. It is also absolutely legitimate. The sell (sorry for the word) crap. They lie and cheat (well other companies do so as well). And they try to dominate all business. This is not good for us (this means all the other human beings). Also the company and all its bigger owners are rich enough to stop earing more profits. but have you seen them stopping? Nope. Therefore they can be hated. At least I find them disgusting. And no this has nothing to do with enviousness on my side.
Or how about you stop claiming that if everyone else does it, then its ok. There is no other industry where shipping defective products is an acceptable business standard. One, thats 1, bug is to many. It isn't OK for Microsoft, Apple or Red Hat. If my roofer only made one mistake they sure as hell would fix it for free. But in virtual world, "bugs" are ok. It isn't like someone could die, so their is no responsibility.
Fair enoughish. To discount that as a Microsoft behavior is a little naieve given their consistently horrible track record, but I do agree it is a bit far out there in this context. The big issue I have is that Apple wasn't deliberatly trying to impair users (though fixing their flaw did impair users from coloring outside the lines with the device they purchased. Microsoft does deliberately impair their users with shit like WGA.
The only change I can believe in is what I find in my couch cushions.
Heh... I haven't had my 4GB Zune long (it was an x-mas gift), but mine has been working flawlessly since I started using it. Contrast that with my wife's 2G iPod Nano. It locks up, skips songs, decided to repeat one song over and over and over again. Since I load the songs on it, I get to experience the horror that is iTunes. People say MS makes bloated, slow software? Apparently these people haven't used iTunes. The Zune software is so much easier to use it's not funny. I thought Apple was supposed to "just work," but the Apple store's only advice is "maybe it's time for an upgrade." She wants to upgrade... but not to another iPod.
Wow, fanboy much? WGA hasn't been a problem for anyone I know. I doubt it's a problem for most people, except those sold the same key by some jackass reselling the same license over and over again.
As for as your bribery goes, I'm willing to bet that any company that hasn't been slapped by the government ever, and then does get slapped would do the exact same thing. The attitude was probably "they haven't been bothering us, so why spend the money." Of course once the government did take aim (legitiately or not), can you blame them for wanting to voice their side of issues?
It's one thing to swack about lobbiests, but to blame ONE company for engaging in the same practices every other company does, well, it's just being a fanboy (or anti-fanboy).
Since year started with a one-year lag from origin and is pre-incremented, the year doesn't need correcting at the end. Assuming of course a definition of IsLeapYear( int year ) returning 1 when true.
Oh, say does that Star-Spangled Banner entwine / The myrtle of Venus with Bacchus's vine?
Dates, despite the enormous historical knowledge of how to treat them, remain a mystery to most computer people.
When has Microsoft ever actually done that? Apple has released updates that DELIBERATELY bricked devices (jailbroken iphones for one), but that's ok
Apple release an update that functioned perfectly on correctly configured devices. If you chose to overwrite the provided code with your own code (the jailbreak) then you have taken update responsibility for your code. Should Apple be responsible for "your" code any more than GM should be responsible for you putting diesel into a gas engine vehicle?
I really shouldn't feed the troll.
The cesspool just got a check and balance.
What's with all these posts about leap year calculation? The leap year code is fine, and works as it should. It's the ConvertDays function that has a problem, an infinite loop that only occurs on the last day of a leap year. It would be helpful if you actually knew the problem before supplying an answer...
You seem to be in great pain. Consider sitting on a chair rather than on the point of a broom handle.
jsut athnoer menagiensls ltitle psrhae for you to dcoede. Why do we wtsae our tmie dnoig tihs?
..., and you'd be crazy to run Windows on anything but MS Dos if you knew how much patching it needed to do.
You'd be crazy to run Windows on anything, period.
(yeah, mod me down, I just couldn't resist)
/var/run/twitter.sock is a twitter socket puppet.
This is driver code, so yes, the standard library is in all probability not available! (shocking)
Those who would give up liberty to obtain working drivers, deserve neither liberty nor working drivers.
People say MS makes bloated, slow software? Apparently these people haven't used iTunes.
I've always wondered why people don't complain about iTunes more. It's such a pain in the ass to have to use it. I just want to drag & drop files and folders onto the mounted device and have it just work. Of course, I made the mistake of buying a Sansa Clip (because it's dirt cheap and works well) and now I have to use Windows Media Player, which is comparably bad.
Sweet, a car analogy.
Imagine this, then: You purchased your car and made modifications so that it could run on diesel as well. Then GM comes along while you are at work and silently takes off your modifications, damaging your car the next time you try to start it up. What then?
As long as I get mine I could care less if I satisfy your mom.
Well now you know one. That first goaround of WGA triggered false positive on my wife's Dell desktop. I called MS and they just said "purchase a new copy". So fuck that...legit OEM locked out because their stupid thing went false positive and their solution is for me to buy ANOTHER legit copy of their crap? I eventually had to dig up the disable WGA crap to get it usable again. Now at work, I have had their stupid activation bullshit screw me on multiple occasions because we have had to recover from failed hardware, try and boot the machine elsewhere and it immediately goes into expired activation mode. Now sometimes it reactivates without trouble, but almost every time I have done it it failed and MS is helpful enough to tell me "sorry, reinstall with a new copy". Having the default status of a criminal with their support staff for being a customer is total bullshit.
Convicted monopolist, punishment with no teeth. That isn't quite the same as practices every other company does. To say Microsoft engages in the same behavior as everyone else is laughable at best. It is a tremendous insult to the numerous tech industry companies that don't engage in the same kind of bullshit.
Apple, Secure Computing, Cisco, and a few others have gone out of their way to provide incredible support in my experience. As far as commercial OS goes, OS X and Solaris both require neither product keys nor some silly bullshit call home activation crap, let alone a tool that constantly calls back to check to see if it should lock you out at the whim of it's masters. Apple can be a little control freak about their stuff, but they sure as hell don't take the same consumers = criminals approach that MS takes.
The only change I can believe in is what I find in my couch cushions.
Nothing is immune from bugs. A "don't touch" comment is the result of irrational confidence that no programmer should ever have. I would suggest "If you think this is wrong, prove it!"
This is a boring sig
http://xkcd.com/292/
"I could restructure the programs flow | or use one little 'goto' instead | How bad can it be?"
Have you ever written a piece of software? Ever? I mean something a bit more than "hello world". It's next to impossible to find every single possible bug there is. Some bugs are easier to find than others, but it's just impractical to try to find them all.
Now scale that up to super huge projects like Linux and Windows and it's insane the amount of bugs that will crop up. You're being unrealistic to say the least. It's the equivalent to you demanding that every single corn flake in a packet of corn flakes is the exact same size and shape and has no broken-off bits or anything.
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
Sweet.
Let's correct the scenario though. GM offers you a CPU fix. You decline and all is well. If you accept, however, they yank the old one, replace it with the new one, and remove that "extra" wire in the process as it's not part of their configuration. Now your mods have broken the rest of the vehicle. OMG!!! Who's at fault?
If you're going to mod your system, you, and only you, can maintain it beyond that point.
The cesspool just got a check and balance.