Slashdot Mirror


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."

465 comments

  1. Why is this a surprise? by deanston · · Score: 0, Troll

    And who uses Windows CE?

    1. Re:Why is this a surprise? by panoptical2 · · Score: 3, Informative
      As Wikipedia would have it here...

      Windows Mobile is best described as a subset of platforms based on a Windows CE underpinning. Currently, Pocket PC (now called Windows Mobile Classic), SmartPhone (Windows Mobile Standard), and PocketPC Phone Edition (Windows Mobile Professional) are the three main platforms under the Windows Mobile umbrella. Each platform utilizes different components of Windows CE, as well as supplemental features and applications suited for their respective devices.

      So, every smartphone/PDA that currently uses Windows Mobile uses some form of CE.

    2. Re:Why is this a surprise? by jcarkeys · · Score: 1

      But none of the devices that use Windows Mobile also use this driver.

    3. Re:Why is this a surprise? by winphreak · · Score: 1, Interesting

      Also, most GPS units use some form of CE, but afaik it's all old versions that're pretty cut up to only do the basics. So I really doubt the driver issue would apply to them either.

      --
      "I'm a well-wisher, in that I don't wish you any specific harm."
    4. Re:Why is this a surprise? by mrsteveman1 · · Score: 1

      AT&T u-verse has some set top boxes running Win CE

    5. Re:Why is this a surprise? by ozphx · · Score: 4, Insightful

      Lots of things use Windows CE, which is fine.

      The problem is with the Freescale Semiconductor's* RTC driver. So if you aren't using that specific chip and driver then CE is unaffected.

      * No, this doesn't excuse MS from proper QA.

      --
      3laws: No freebies, no backsies, GTFO.
    6. Re:Why is this a surprise? by Tony+Hoyle · · Score: 1

      Most? TomTom and Garmin are both Linux, and that's a huge chunk of the market right there.

  2. Wow. by LeadLine · · Score: 4, Funny

    It wasn't a bug! It was an unexpected feature!

    Microsoft is taking a stance against teenagers blowing their ears out with loud music.

    1. Re:Wow. by XPeter · · Score: 0

      Hey! I'm a teenager who proudly blows my ears out with Metallica daily, you insensitive clod!

      --
      "The difference between genius and stupidity is that genius has it's limits" - Albert Einstein
    2. Re:Wow. by Vadatajs · · Score: 3, Funny

      Teenagers these days are too young to remember metallica.

    3. Re:Wow. by Yvan256 · · Score: 4, Funny

      They're too busy listening to NiMHica.

    4. Re:Wow. by Anonymous Coward · · Score: 0

      Teenagers these days are too young to remember metallica.

      you know they did just release a new album...

    5. Re:Wow. by stonedcat · · Score: 0, Funny

      Hey, if he wants to blow Metallica then by all means, let him.

      Who are we to stand in the way of his dreams?

      --
      You can't take the sky from me.
    6. Re:Wow. by Anonymous Coward · · Score: 5, Funny

      No they didn't no they didn't lalalala I can't hear you That piece of shit was definitely not any Metallica I know.

    7. Re:Wow. by MartinSchou · · Score: 1

      I would have gone for Meitnerium Tantalum Lithium Calcium

    8. Re:Wow. by Barny · · Score: 3, Informative

      Metallica?

      Damn you young kids these days. /me cranks motorhead back up while yelling to "git off his lawn!"

      --
      ...
      /me sighs
    9. Re:Wow. by Anonymous Coward · · Score: 0
      It wasn't a bug! It was an unexpected feature!

      Exactly!

      I mean, what about "Microsoft Product" did those Zune buying weenies not understand?

    10. Re:Wow. by mrsteveman1 · · Score: 1

      Yes and where were you when funny man up there was writing his bad joke? Eh?

    11. Re:Wow. by Tekzel · · Score: 1

      I would have agreed before Death Magnetic (dumb name), as everything since the black album has been trash and not worth listening to. But, their latest album is awesome, so all bets are off.

    12. Re:Wow. by joaommp · · Score: 2, Funny

      you can't hear him because you blew your ears with your loud Zune.

    13. Re:Wow. by Necrobruiser · · Score: 2, Funny

      I guess you didn't realize that Metallica didn't stop after 1986.... ;)
      http://bash.org/?197845

      --
      "I planned within my means and got a fixed rate mortgage, so where's MY bailout?" -cafepress
    14. Re:Wow. by Jedi+Alec · · Score: 1

      Damn you young kids these days. /me cranks motorhead back up while yelling to "git off his lawn!"

      Should go well with "The Ace of Spades", just the right number of syllables. Now just picture Lemmy singing it...

      --

      People replying to my sig annoy me. That's why I change it all the time.
    15. Re:Wow. by KDR_11k · · Score: 1

      They released another one after St Anger.

      --
      Justice is the sheep getting arrested while an impartial judge declares the vote void.
    16. Re:Wow. by KDR_11k · · Score: 1

      Have they released a fixed version of it yet? From what I read the retail CD version sounded a lot worse than the Guitar Hero DLC version.

      --
      Justice is the sheep getting arrested while an impartial judge declares the vote void.
    17. Re:Wow. by Dun+Malg · · Score: 1

      Motorhead rules. Back around '95 I did speed with Lemmy at the Rainbow in Hollywood. The bastard beat me at Ms Pac Man two dozen times, but he did buy me a drink. Class act all the way. My drug days are over, but I still rate all music I hear on "The Motorhead scale of 1 to 10, Motorhead being 10".

      --
      If a job's not worth doing, it's not worth doing right.
  3. Warning, Y2.1K bug. by LostCluster · · Score: 3, Informative

    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.

    1. Re:Warning, Y2.1K bug. by Yvan256 · · Score: 2, Funny

      What about other years which are multiples of four, also multiples of 100 but not multiples of 400?

    2. Re:Warning, Y2.1K bug. by LostCluster · · Score: 5, Informative

      Here's your 500 year plan:

      1900 - multiple of 100, not a multiple of 400, no leap day.
      2000 - was a multiple of 100, but also a multiple of 400 so we still had a leap day.
      2100 - see above
      2200 - not a multiple of 400, no leap day.
      2300 - not a multiple of 400, no leap day
      2400 - multiple of 400, so have the leap day anyway.

    3. Re:Warning, Y2.1K bug. by Gothmolly · · Score: 2, Insightful

      No need to hard-code, there's an established algorithm for computing this.

      --
      I want to delete my account but Slashdot doesn't allow it.
    4. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0


      year=2100;
      leap = false;
      if ((year %4 )==0) leap=true;
      if ((year %100)==0) leap=false;
      if ((year %400)==0) leap=true;

      this works

    5. Re:Warning, Y2.1K bug. by LostCluster · · Score: 0, Troll

      Okay, tell the programming instructors that there's no need to teach Hello World examples, because there's already code that does that.

    6. Re:Warning, Y2.1K bug. by narcberry · · Score: 3, Insightful

      I think you missed the point.

      --
      Modding me -1 troll doesn't make me wrong.
    7. Re:Warning, Y2.1K bug. by gcnaddict · · Score: 2, Funny
      It won't matter:

      #define ORIGINYEAR 1980 // the begin year
      #define MAXYEAR (ORIGINYEAR + 100) // the maxium year

      --
      Viable Slashdot alternatives: https://pipedot.org/ and http://soylentnews.org/
    8. Re:Warning, Y2.1K bug. by jrumney · · Score: 1

      In a consumer electronics product that's launching anytime before about 2075, I don't think I'd bother. Remember all the software that needed fixing for 2000 because some idiot had put in the 100 year rule without the 400 year rule? Would have been much better to just keep it simple and reduce your list of things to go wrong.

    9. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      This isn't important only on products that are to be used on year 2100. I - as someone who is not a programmer - would imagine this thing to come up as one way or another on any software handling dates at/past that point. And it is easy to imagine that kind of software.

    10. Re:Warning, Y2.1K bug. by gcnaddict · · Score: 2, Insightful

      The code in the freescale driver actually covers this. Check the IsLeapYear() function in the code (line 162):

      static int IsLeapYear(int Year)
      {
      int Leap;

      Leap = 0;
      if ((Year % 4) == 0) {
      Leap = 1;
      if ((Year % 100) == 0) {
      Leap = (Year%400) ? 0 : 1;
      }
      }

      return (Leap);
      }

      --
      Viable Slashdot alternatives: https://pipedot.org/ and http://soylentnews.org/
    11. Re:Warning, Y2.1K bug. by AmberBlackCat · · Score: 1

      We'll get right on that...

    12. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 5, Funny

      For Slashdotters you lot seem pretty confident the Zune is going to be around for awhile.

    13. Re:Warning, Y2.1K bug. by jrumney · · Score: 2, Insightful

      It's easy to imagine such software in a general computing environment, especially in the financial and insurance arenas where people might be taking a long term view or processing historical data, but in a single purpose consumer electronics product?

    14. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 2, Interesting

      That doesn't seem to be the best way to write that code: I would imagine something more like:

      static int IsLeapYear(int Year)
      {
      if ((Year % 400) == 0) return 1;
      if ((Year % 100) == 0) return 0;
      if ((Year % 4) == 0) return 1;

      return 0;
      }

    15. Re:Warning, Y2.1K bug. by hobbit · · Score: 1

      I think you'll find that most "Hello World" examples use standard libraries (e.g. helloworld.c uses printf).

      --
      "Wise men talk because they have something to say; fools, because they have to say something" - Plato
    16. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      I - as someone who is not a programmer

      Uh. What?

    17. Re:Warning, Y2.1K bug. by PIBM · · Score: 5, Insightful

      Actually, it's far from being good. In 99% of the cases you will do 3 modulos operation, in 0.75% you will do 2 modulos and in 0.25% you will do 1 modulo, for an average modulo cost of 2.9875 per run.

      With the initial solution, you have 1 modulo in 75% of the cases, 2 modulo in 24% of the cases, and 3 modulo in 1% of the cases, for a total average modulo cost of 1.26 per run.

    18. Re:Warning, Y2.1K bug. by 4D6963 · · Score: 2, Insightful

      The problem with CS graduates is too often that they try to reinvent something (poorly) when they should do some digging first, not so much that they're unable to work out a solution.

      --
      You just got troll'd!
    19. Re:Warning, Y2.1K bug. by kybred · · Score: 5, Informative

      No need to hard-code, there's an established algorithm for computing this.

      Why not call it by its name: Zeller's Congruence.

    20. Re:Warning, Y2.1K bug. by danwesnor · · Score: 1

      I thought the point of Hello World was to teach students how to compile & link.

    21. Re:Warning, Y2.1K bug. by danwesnor · · Score: 2, Funny

      Umm, no, that code had to change because everybody used 2 ASCII characters for the year instead of four, or instead of just using a 16 bit integer that would have taken the same space and lasted another 63k years. At least, I hope so, COBOL really shouldn't have been allowed to survive past 1990.

      Maybe those coders were making a point, that being "Anybody who's still using this senseless language in 2000 gets what they deserve."

    22. Re:Warning, Y2.1K bug. by Chysn · · Score: 1

      > Here's your 500 year plan:

      Or generalize with code (Python here) for a forever plan:

      ly = not y % 4 and y % 100 or not y % 400;

      --
      --I'm so big, my sig has its own sig.
      -- See?
    23. Re:Warning, Y2.1K bug. by Chysn · · Score: 1

      And now that I think about it, some parentheses help make it understandable:

      ly = (not y % 4) and (y % 100) or (not y % 400);

      --
      --I'm so big, my sig has its own sig.
      -- See?
    24. Re:Warning, Y2.1K bug. by jrumney · · Score: 1

      The Federal Aviation Administration, for example, found that when its computers are fed flight information for Feb. 29, 2000, they inform the user that there is no such date.

      --James Coates, "Da mare on da net," Chicago Tribune, February 16, 1998

    25. Re:Warning, Y2.1K bug. by djupedal · · Score: 1

      The scenario involved a 'leap second' not a leap year, which might explain why MS & Toshiba got it wrong if they focused on a leap year...

      "An extra day was tacked on to February in 2008 and by international agreement, the world's timekeepers also added a "leap second" to Dec. 31 to keep Earth apace with very precise clocks."

    26. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 5, Funny

      I can't help but imagine how I would be directed by work to "solve" this problem.

      First, they would tell me that it's too difficult, expensive, and complicated to implement the correct solution. Even if I gave them a working prototype, they wouldn't change their minds.

      Then they would tell me "just assume every 100th year is not a leap year." So I would do that instead. In the time from 2100 to 2400, they would say that "a better solution is due to come out next quarter." They would say this every quarter for 299 years.

      In 2399, they would finally give me permission to fix the problem. But the leap year-calculating code works, and they don't want me to mess with it. Instead, they'd tell me to add a test when the program starts to see what year it is. If it's 2400, then it will refuse to run. (We'll definitely have a better solution in place by Q1. Definitely.)

      But the program often runs for an extended period of time without being restarted, so it's possible that someone will start it in December 2399 and it will still be running in February/March 2400. Management has a simple fix for this one: calculate the average run time for the program, add a margin of error, and use that to determine the actual "upper limit" on when the program is allowed to start. My boss would be really excited about this, because it would allow us to refine our earlier not-after-January-1st estimate to be "completely accurate."

      Unfortunately, we don't know the average run time for this program. So I'm told to add code to it to track when it starts and ends and store the results in a file. When the program starts, it examines that file (in addition to recording its own start time), calculates the average run time, adds 10% (there are still director-level meetings about whether we should round up to the nearest hour or day), and subtracts that value from February 28th, 2400. If the current timestamp is greater than or equal to the result we got from that, the program won't start.

      That's pretty good, but my boss would be worried about the program crashing. If that happens, after all, we won't know the program's end time -- never mind that it's November by now and there's no chance of getting useful data no matter what -- so instead of logging an end time, the program logs a heartbeat every minute. Now, you can determine when the program ended -- to within a minute! -- simply by looking at the heartbeat timestamps. When you encounter a gap of more than 1 minute (plus a small margin of error), you know the program ended. This has the bonus, my boss tells me, of simplifying the design by only requiring you to log one type of message to the file. He also assures me that this "telemetry data" has the potential to be "really useful for data mining." He talks about adding information on CPU time consumed, memory in use, I/Os, all sorts of stuff, then putting it in a database to be retrieved later. I manage to talk him out of it by pointing out that "the better solution [with which I am completely uninvolved] will be out in just a few months, so you should just make sure it makes it into that instead."

      Not that I'm bitter.

    27. Re:Warning, Y2.1K bug. by JackieBrown · · Score: 2, Funny

      No, it's used to discover leap year bugs

    28. Re:Warning, Y2.1K bug. by Bozdune · · Score: 4, Insightful

      If my code's still running in 2100, our society has got way bigger problems than me not figuring leap years correctly.

    29. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      yeah, but who's to say that your POS code will still be running in another 91 years?

    30. Re:Warning, Y2.1K bug. by trolltalk.com · · Score: 1

      "It's easy to imagine such software in a general computing environment, especially in the financial and insurance arenas where people might be taking a long term view or processing historical data, but in a single purpose consumer electronics product?"

      The single purpose of the Zune is to make its' owners look stupid. The leap year problem is therefore both a feature AND a bug.

    31. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      The same guys who have the sales/inventory staff at various large retail outlets who will remain anonymous using dos based/serial based apps from the 80's on Windows XP systems instead of having a nicer more userfriendly GUI application that doesn't allow them to accidentally overwrite a character with another character that won't actually be saved in its place. (I saw this happen years ago at a job I was at. There were plenty of other screwed up software solutions there as well that required either excessive time, or constant rebooting to get done with trivial tasks that should've been automatable to your selections in under 10 minutes.

    32. Re:Warning, Y2.1K bug. by lyml · · Score: 3, Insightful

      That's just silly, readability trumps over using modulo a thousand times. Always, with no exceptions.

    33. Re:Warning, Y2.1K bug. by rilian4 · · Score: 3, Funny

      tested your algorithm. It breaks where y%100 is not 0..at least in python 2.5x using windows idle.

      I found the following more accurate:
      def leapyear(y):
              y4=True
              y100=True
              y400=True
              if y%4==0:
                      y4=False
              if y%100==0:
                      y100=False
              if y%400==0:
                      y400=False
              ly=(not y4) and (y100) or (not y400)
              return ly

      Might not be the most efficient but it works as far as I can see.

      --

      ...quicker, easier, more seductive the darkside is...but more powerful, it is not.
    34. Re:Warning, Y2.1K bug. by gzipped_tar · · Score: 1

      And as a reminder, the Julian Calendar prevailing before the Gregorian used to have bugs in its leap year algorithm. This only affect very old dates dating back to Roman era but yes, it was indeed a bug. Also, the requirement of being a multiplication of 400 for century years is a Gregorian feature that was absent in the Julian Calendar.

      --
      Colorless green Cthulhu waits dreaming furiously.
    35. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      Did we work together at my last job?

    36. Re:Warning, Y2.1K bug. by gzipped_tar · · Score: 1

      Sorry for replying to myself, but what I was trying to say is that a program dealing with old dates should be made bug-compatible rather than correcting the "bugs". Of course, given the varied usage and interpretation of the old calendar, a better approach is to make the behavior configurable while providing a reasonable default.

      --
      Colorless green Cthulhu waits dreaming furiously.
    37. Re:Warning, Y2.1K bug. by Anonymous+Brave+Guy · · Score: 1

      Well, if there's one thing we learned last century, it was never to bet against the longevity of a Microsoft product so bug-ridden that no sane person would ever use it...

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    38. Re:Warning, Y2.1K bug. by scienceprogrammer · · Score: 0, Offtopic

      Oh my God someone should fix that before society colapes
      I just checked windows and no 2/29/09 it was there last year. Strange.
      Think I'll write a book tell everyone to move to the mountains and stock up on duck tape.

    39. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      Wrong. The scenario involved a bug involving handing of leap years. It was calculating some date as number of days since January 1st and had > 366 as a case. Why exactly it broke at 2AM I don't know, but there was no leap second handling in these devices. In fact, I don't think any software has automatic knowledge of leap seconds, and I'd be very surprised if the Zune tried to. In general, if my personal media player is one second behind every 3 years or however long they decide to add those things, I'm fine with it - my computer will have fixed its time when it synced anyway, I hope.

    40. Re:Warning, Y2.1K bug. by celtic_hackr · · Score: 1

      Well that's true only if you only run the calculation once a year, or you are expecting your code to continue in use for a hundred years or more. Since the code is likely to be run maybe hundreds of times a day, the percentages using the original solution vary in the near term. While the code might run for decades, it is unlikely to run for century. So while your numbers are true and accurate for very large spans of time, for the next 90 or so years it'll be 75% one modulo and 25% two modulo or 1.25 modulo on long term average. But for any given year it'll be either 1 modulo or 2 modulo.

    41. Re:Warning, Y2.1K bug. by Marcos+Eliziario · · Score: 1

      Really,

      One should not necessarily need to have this on his head like GP.

      But, there is any excuse for a programmer these days not to look up on google to see if there's an established algorithm for doing things like this?

      I mean, Something like http://www.google.com.br/codesearch?hl=pt-BR&lr=&q=Zeller's+congruence+lang%3Ac ???????

      I mean: this code almost SCREAMS out loud "I am a piece of shit, surely there must be a more intelligent way of calculating leap years instead of doing such a stupid and ugly loop"

      If you are going to reinvent the wheel, at least make sure it doesn't have any fucking vortexes.

      --
      Your ad could be here!
    42. Re:Warning, Y2.1K bug. by PIBM · · Score: 1

      That's why that's a full time average and not for specific years. Notice that your short them average (4 years to 99 years) gave 1.25 as the result, rather than 1.26 for a standard average.

      I don't think it was worth pointing out ;)

    43. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 3, Insightful

      Yuk. Unreadable tripe. It's basically the same algorithm, implemented very poorly. Try:

      def isLeapYear(year):
              return (year % 4 == 0 and (not year % 100 == 0)) or (year % 400 == 0)

    44. Re:Warning, Y2.1K bug. by Chysn · · Score: 1

      > It breaks where y%100 is not 0.

            That's interesting. I don't have 2.5 (using Python 3). Do you have an example of a year that returns the wrong result under Python 2.5? This was just a five-minute exercise, but I'd like to figure out what the difference is. Did they change the order of operations in Python 3?

      --
      --I'm so big, my sig has its own sig.
      -- See?
    45. Re:Warning, Y2.1K bug. by PIBM · · Score: 2, Informative

      Insightful ?

      I believed it was a joke.. We are speaking of embeded devices with a very limited amount of resources to spare, and it was already very well readable along with being written in the way it's usually described.

      Haven't you learned that it's a leap year every 4 year first, then later on someone taught you it wasn't every 100 years even if divisble by 4, and then there's an exception if it's divisible by 400 where it's still a leap year, or they started in the reverse order?

      Also, what if the chosen fractions (100 / 400) to split the time were not chosen to be a multiple of each other ? Reversing the equation would not work in that case.

    46. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      #define isLeapYear(Year) (!(Year&3)&&((Year%25)|!(Year&15)))

    47. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      Thats about 500 dilberts right there.

      How remarkably recognizable...

    48. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      Yeah if it were properly optimized you'd be able to save on nearly 3 modulo operations... EVERY YEAR!

      Wow!

    49. Re:Warning, Y2.1K bug. by Failed+Physicist · · Score: 1

      And then people wonder why their blazing fast quad-core equipped new computer doesn't really feel faster than that 800mhz running win2k in the corner.

      Feature bloat is not the only problem. Lazy programming is much worse.

      Give me a single reason why you would do the second implementation instead of gcnaddict's. Readability? Hah! I've spent probably less than 5 hours coding in my whole life yet I could understand (by transliterating to pseudo-code) his algorithm as easily as I could the slower, ressource-hog version.

      I can't help myself to think that if you really believe what you said, you are a shame to the programming profession.

      Also, get off my lawn.

    50. Re:Warning, Y2.1K bug. by jcr · · Score: 3, Insightful

      COBOL really shouldn't have been allowed to survive past 1990.

      I disagree. I wouldn't want to write a 3D CAD program in it, but COBOL is still a fine choice when the task at hand is to account for a million monthly utility bills. The built-in BCD arithmetic is very well suited for implementing financial applications, and COBOL isn't susceptible to buffer-overflow bugs like the C-based languages are.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    51. Re:Warning, Y2.1K bug. by laejoh · · Score: 1

      You forgot:

      2101 - war was beginning

    52. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      If you don't find gcnaddict's code readable then you should give up your geek card and keep yourself away from any programming-related forum.

    53. Re:Warning, Y2.1K bug. by fbjon · · Score: 1

      I really don't think it's the degree that causes that problem.

      --
      True confidence comes not from realising you are as good as your peers, but that your peers are as bad as you are.
    54. Re:Warning, Y2.1K bug. by johannesg · · Score: 1

      You must have some stories to tell... Any chance of seeing some of them on thedailywtf? They seem to be in need of good WTF's lately.

      And I suppose you probably don't want to tell us where you work? :-)

    55. Re:Warning, Y2.1K bug. by PIBM · · Score: 1

      How many calls to this function is used up ?

      Guess ?

      Just for a single date computation this year it will use 29 calls to the is_leap_year function. No guesses on the total number of date computation being done per day has been done yet, which could be a fair amount.

    56. Re:Warning, Y2.1K bug. by 4D6963 · · Score: 1

      Who said it was?

      --
      You just got troll'd!
    57. Re:Warning, Y2.1K bug. by danwesnor · · Score: 1

      If BCD arithmatic (which is inefficient in both speed and storage space) is the only virtue you can find in a language, then the language isn't worth using.

    58. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      what the hell, this is 2007, not 1977!
      who cares if it does 3 modulo ops by god.

      the point is that the proposed code is clearer and harder to fuck up. you know, the reason we're reading this slashdot story in the first place...?

    59. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      y4=True
      [ ... ]
                      if y%4==0:
                                      y4=False
      [ ... ]
                      ly=(not y4) and [ ... ]

      Are you a hardware engineer? Why the negative logic?

    60. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      but it's possible to write a even more efficient function:

      int leap_version_5(int year){

              if(year&0x03) return 0;

              if(0==(year&0x0f)) return 1;

              if(year%100) return 1;

              return 0;

              }

      this version virtually only calculate less than 0.25 modulo per year, the true is that computes 1.5 modulo but using a numeric-binary properties.
       
      year&0x03 is equivalent to year%2
      year&0x0f is equivalent to year%16 and because 16*25=400,75*4=300,8*25=200, 4*25=100 and 16=4*4 is equivalent to year%400 for this case.

    61. Re:Warning, Y2.1K bug. by FunkyELF · · Score: 1

      Its already in calendar.py def isleap(year):
      """Return 1 for leap years, 0 for non-leap years."""
      return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

    62. Re:Warning, Y2.1K bug. by mdielmann · · Score: 1

      If my code's still running in 2100, our society has got way bigger problems than me not figuring leap years correctly.

      I think I hear the cries of programmers in the 1960's who said something very similar...and 91 years isn't that much more than 40 years...

      --
      Sure I'm paranoid, but am I paranoid enough?
    63. Re:Warning, Y2.1K bug. by jcr · · Score: 1

      Try reading for comprehension. I didn't say that BCD was the only virtue in the language.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    64. Re:Warning, Y2.1K bug. by StikyPad · · Score: 1

      Well that, plus the world's going to end in 2012.

    65. Re:Warning, Y2.1K bug. by danwesnor · · Score: 1

      What was the other one? No buffer overflows? COBOL prevents this by denying the programmer direct access to memory, which I don't consider a virtue. Slowing down everybody's code by checking every array access is not better that requiring programmers to be disciplined. An out-of-bounds array access is still a programmer error, whether it was caught by the run-time environment or not.

    66. Re:Warning, Y2.1K bug. by plague3106 · · Score: 1

      The device itself, or the software? I admit I haven't had it that long, but it's been flawless for me. I was surprised about the reports of mass zune hangovers... my 4GB was just fine.

    67. Re:Warning, Y2.1K bug. by plague3106 · · Score: 1

      Ya, I think you missed the OTHER Y2K problem, which was exactly what the OP said it was. There were two issues with Y2K, not just one.

    68. Re:Warning, Y2.1K bug. by Khyber · · Score: 1

      My solution further down in the comments eliminates the need for algorithms altogether. Why not just use a simple compressible table for referencing known leap years? As it is I can rattle off the next 50 leap years without thinking. Reference the table, if year = known leap year then February = 29 days. Most consumer-level software, hell most COMMERCIAL software won't last through 50 leap years.

      You don't need some complicated and flawed algorithm to do something that damned simple, do you?

      --
      Still waiting on Serviscope_minor to wake up to fucking reality and realize that Jessica Price isn't going to fuck him.
    69. Re:Warning, Y2.1K bug. by ByteSlicer · · Score: 1

      year&0x03 is equivalent to year%2

      No it isn't. It is equivalent to year%4 (the result of the AND is 0..3).
      And also: according to your function, 64 is a leap year...

    70. Re:Warning, Y2.1K bug. by tprime · · Score: 1

      You're a COBOL coder, aren't you......

      --
      http://www.tomandemily.com
    71. Re:Warning, Y2.1K bug. by gknoy · · Score: 1

      If my code's still running in 2100, our society has got way bigger problems than me not figuring leap years correctly.

      The temporary nature of one's code (especially since we almost always underestimate the lifespan) is no excuse for being sloppy.

    72. Re:Warning, Y2.1K bug. by jcr · · Score: 1

      You're a COBOL coder, aren't you...

      Not really. I only dabbled with it a bit back when I was in high school.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    73. Re:Warning, Y2.1K bug. by jcr · · Score: 1

      Slowing down everybody's code by checking every array access is not better that requiring programmers to be disciplined.

      Subscribe to Bugtraq for a couple of years, and see if you still believe that.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    74. Re:Warning, Y2.1K bug. by Bozdune · · Score: 1

      I suggest that you carefully peruse the web and see if you can locate a reliable purveyor of a sense of humor.

    75. Re:Warning, Y2.1K bug. by rilian4 · · Score: 0

      2004 and 2008 both returned an integer "4" using the original algorithm instead of a true or false value.

      --

      ...quicker, easier, more seductive the darkside is...but more powerful, it is not.
    76. Re:Warning, Y2.1K bug. by Anonymous Coward · · Score: 0

      64=4*4*4,i think that is a leap year. I tested leap_version_5 to the others leap year functions and the output is always the same.

    77. Re:Warning, Y2.1K bug. by LostCluster · · Score: 1

      Sure you didn't mean 2001? We seemed to started going downhill in late January of that year.

    78. Re:Warning, Y2.1K bug. by AgBullet · · Score: 1

      If my code's still running in 2100, our society has got way bigger problems than me not figuring leap years correctly.

      You don't need your code to still be running in 2100 to reference dates in 2100. Simulation software, for one, might easily need those dates for predictions.

    79. Re:Warning, Y2.1K bug. by celtic_hackr · · Score: 1

      Actually, I was trying to point out the later comment. That in actual use you'll never see 1.25 or 1.26, but 1, 2 or 3. Sure you can average it out, but for any given year every time it runs you'll have 1, 2, or 3 modulo. Averaging it out is really kind of pointless other than for educational purposes.

    80. Re:Warning, Y2.1K bug. by ByteSlicer · · Score: 1

      Well, it all depends on which calendar you use. The Gregorian calendar wasn't introduced until 1582 AD, and so there where no actual leap years before that date.
      If one would extrapolate the Gregorian calendar into the past (the so called Proleptic Gregorian calendar) then your formula would give the correct answer.

    81. Re:Warning, Y2.1K bug. by PIBM · · Score: 1

      Ok, but you failed to look at what this function is used in the context of the zune.

      In this case, everytime the current date is looked up, it needs to compute the is_leap_year function for every year since 1980, thus causing many of the cases from being used, ie, it's not always computing is_leap_year(CURRENT_YEAR).

      This is why the average modulo cost is usefull, since the real cost of the date computation would be defined as sum(modulo_cost(is_leap_year(y)), y=1980..CURRENT_YEAR)) which we can evaluate as being close to (CURRENT_YEAR - 1980 + 1) * average_modulo cost. (+1 is used if 1980 is not precomputed)

      In our case 2009 - 1980 + 1 = 30
      30 * 1.26 = 37.8 => 38 modulo operations for obtaining the current date.

      And, actually, since we recently went over a 100 year milestone, the average usage will be very close to a 1.26 value.

      So, evaluation the average speed of the function in itself coult be pointless, as it's true that whatever you do will result in a 1, 2 or 3 modulo operations, but when you want to make a real usage of the function, and that you want to know which one to use between 2 functions, each using 1, 2 or 3 modulo operations, it's very usefull to be able to compare the real distribution of the values. In our case, it tells us that the date computation would takes 2.37 times less modulo operation (which will most probably be the controlling factor) with the former formula than with the proposed one.

  4. If this interests you by dmomo · · Score: 1

    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.

    1. Re:If this interests you by Creepy+Crawler · · Score: 3, Informative

      Amazon link eh? meh.

      Try this link for your "sampling" : Deep C Secrets.

      Took only 15 seconds for that link. Enjoy.

      --
    2. Re:If this interests you by Anonymous Coward · · Score: 0

      15 seconds was not long enough. You should have checked that thing first.

  5. Some has came up? by Anonymous Coward · · Score: 0

    Methinks it was the same f*cked up code monkey that wrote this summary!

  6. Import calendar? by TurtleBlue · · Score: 5, Insightful

    "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?"

    1. Re:Import calendar? by gcnaddict · · Score: 2, Interesting

      Well, that might explain why the same clock doesn't exist in the subsequent Zunes, but who knows.

      I'm more disturbed by one of the comments and the subsequent reply.

      --
      Viable Slashdot alternatives: https://pipedot.org/ and http://soylentnews.org/
    2. Re:Import calendar? by nedlohs · · Score: 2, Insightful

      FOr fuck sake, how do you manage to read that part and not read the part before it: "source code for the bad driver".

      The QA person/people testing the driver for the real time clock better damn well be testing date and time stuff.

    3. Re:Import calendar? by Anonymous Coward · · Score: 5, Informative

      It is driver code supplied by the manufacturer of the hardware platform on which the Zune and a couple of other devices are built. This platform includes a real-time clock which counts seconds since midnight and days since 1/1/1980. Considering that hardware component prices are cut-throat, there is probably no quality management for the software whatsoever. If it appears to work, it ships.

    4. Re:Import calendar? by TurtleBlue · · Score: 5, Insightful

      Thanks - that makes a tad more sense. I see everyone running around blaming Microsoft for the code since their name is on the product, even if it was a 3rd party vendor. They certainly are still liable for all the busted Zunes, but I couldn't imagine Microsoft didn't have *some* C leap-year code sitting around that actually worked, and could be compiled for any chip they wanted.

      Microsoft still has to take the hit up front, but then they'll sue or "renegotiate contracts" with the vendor that supplied the bad driver code, based on what it costs them.

      I'm still shocked that the manufacturer couldn't dig up *some* free/open calendaring code that's was around pre-2004. But hey, at least we know they were honest about not ripping off some other source code and calling it their own.

    5. Re:Import calendar? by nato10 · · Score: 5, Informative

      This is kernel-level code -- part of the OEM Abstraction Layer -- that is used to read the current time from the RTC, hence it is hardware-specific. RTCs on other processors, or Freescale-based devices using external RTCs, may implement the OemGetRealTime () function differently than Freescale has done here (the buggy ConvertDays () function is just a helper function).

    6. Re:Import calendar? by Anonymous Coward · · Score: 0

      More than likely MS didnt even write the code. Some third part did. Their whole driver infrastructure is just built that way... Their test system is just not ready for this sort of thing (it should be). Trust stress out CE a little bit and it starts acting REALLY oddly.

      Dont blame MS here is who you should blame...
      'Copyright (C) 2004-2007, Freescale Semiconductor'

    7. Re:Import calendar? by Anonymous Coward · · Score: 0

      But would you call it a day or a day+1 if it was a leap year?

    8. Re:Import calendar? by AuMatar · · Score: 3, Informative

      It was found in driver code. Part of the goal of driver code is to be as lean and mean as possible- most embedded devices do not have a lot of rom space- what they have is measured in MBs, not GBs. Remember not all the world is cell phones and mp3 players. In that case writing your own leap year function is the correct answer- existing calendar libraries likely have far more functionality than you need and would blow out your size. Given a choice between statically linking an entire calendaring library and writing a simple IsLeapYear function, writing the leap year function is the correct choice for that environment.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    9. Re:Import calendar? by Anonymous Coward · · Score: 0

      When was the last time you didn't just import calendaring from another library and call it a day?

      Maybe when you are the operating system vendor, and you ARE the ones writing the library?

    10. Re:Import calendar? by profplump · · Score: 4, Informative

      It's really probably not. Most of the basic calendar functions in libc (or glibc or dietlibc or uLibc) were written for 8 MHz machines running with 1 MB of system memory -- they'd do just fine on your embedded system.

    11. Re:Import calendar? by azenpunk · · Score: 1

      why isn't there a way to pull only the functions out of a library that you need to use, so you can still use libraries for efficiency when writing but still not have to have the space for the whole thing?

      or are things like that possible or not enough for an application like this?

    12. Re:Import calendar? by TrekkieGod · · Score: 3, Informative

      It was found in driver code. Part of the goal of driver code is to be as lean and mean as possible

      He failed. In the function in question he had the number of days since Jan 1, 1980. At the end of the loop, he was supposed to have the number of years since 1980 + the number of days since the beginning of the current year. His solution was to iterate the year beginning from 1980, check to see if it's a leap year, then subtract 365 or 366 days accordingly. The loop would supposedly continue until the desired state is achieved but, because of the bug, became an infinite loop at the end of leap years.

      Not only was his function not "lean and mean" but it actually gets more expensive to run every year that passes :)

      I'm also curious as to why 1980 is the epoch, but that's not as important.

      --

      Warning: Opinions known to be heavily biased.

    13. Re:Import calendar? by Genevish · · Score: 1

      The "flag" for functionality that would need to be tested would be requirements. I would guess the requirements are incomplete in this instance, or poorly written.

      And, as a member of a QA team, I could turn this around and ask, "why did development make this mistake"?

    14. Re:Import calendar? by dbIII · · Score: 1

      Thanks - that makes a tad more sense. I see everyone running around blaming Microsoft

      They designed it and sell it as a unit even if parts are from other places. They have a responsibility to test it. There is no point blaming contractor Y from company X if the place that is ultimatly responsible for the finished product doesn't test it properly.

      Since the point was missed so badly it's time to punish with a car analogy. If a wheel falls off your car you blame Ford for buying dodgy wheel nuts and not whoever sold them the dodgy wheel nuts. If it's sold as a unit it should be tested to see how well it runs as a unit.

    15. Re:Import calendar? by Fulminata · · Score: 1

      When I was in QA, testing edge cases like leap years would be some of the first things to get added to the test plan for something like this. Even if the code responsible for handling it was from a third party.

      Of course, the time dedicated to testing edge cases involving third party code would be the first thing cut by the project manager as deadlines approached.

      I tend to think that's the more likely scenario here rather than the QA guys missing such an obvious test case.

    16. Re:Import calendar? by danwesnor · · Score: 1

      The QA person/people testing the driver for the real time clock better damn well be testing date and time stuff.

      Not to mention boundary conditions.

    17. Re:Import calendar? by Anonymous Coward · · Score: 0

      "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?"

      Dude, the QA dept at the company test all date related functions. Problem is that they do it very stupidly. If they have a project that will be triggered by a new date in the future, they change the time/date on the QA server, which get's them locked out of the windows domain when they forget to set the date back. I;ve asked them to just create a temporary DATE variable in their code to test against, but they will not do it. So, there QA people tend to be dumb.

    18. Re:Import calendar? by Anonymous Coward · · Score: 0

      This platform includes a real-time clock which counts seconds since midnight and days since 1/1/1980.

      Well, there's your problem right there. Everyone knows you count seconds since the unix epoch, 00:00:00 UTC on January 1, 1970.

    19. Re:Import calendar? by jellomizer · · Score: 4, Informative

      Or from a more basic standpoint...
      People make mistakes.

      When testing leap year for a data set you like to see if you have a Febuary 29th and A March 1st, as well the days of the week are updated after the leap day. December 31st isn't on the top of days to check for leap year code.

      Secondly coding for date times even with good prebuilt libraries is a pain. Unfortunately Time and Date are not really good mathematical functions. 365 days a year except for every 4 years where there is 366 The subset of year is split to months where each value is different of having 28, 29, 30, 31 days in it. Then we have 7 days weeks, which do not divide nicely with any other greater time unit (except for the 28 day month, which is only happens once a year... except for a leap year) Now each day has 24 hours, split into 2 12 hour segments, each hour is split up with 60 minutes and then 60 second per minute. Then finally after the second we can start using the Metric niceity in programming. Oh! Oh! don't forget about TIme Zones, and Daylight savings time (which is different per country, state, and follows political lines more then geographic lines.), And if you are going at high speeds for aerospace applications those Crazy Einstine theories come into play.
      Now no one really goes with the same approach to follow all these crazy rules and having a common library is still tricky because we all do different math calculations, also when you do a time++, do you want it one more second like in Unix/Linux OS development or one extra day like in Microsoft SQL. Then when you get these values sorted or a quick search/filter. and you may need to sort them etc. American Time Format doesn't do a good job at this. So we need to switch it to European formats. All in all it is a lot of tough coding all of it is tough to QA Because you need to test all the times to truely know that there is no bugs in it.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    20. Re:Import calendar? by jc42 · · Score: 4, Insightful

      [Microsoft] designed it and sell it as a unit even if parts are from other places. They have a responsibility to test it.

      No, they don't. They have several decades of success selling untested software. Their customers have given them a very strong message: "We don't care about quality or reliability. We only want to buy whatever Microsoft sells. Don't tell us about something from another vendor that's higher quality; we aren't interested."

      They've become a huge success. They're obviously doing what their customers want. They'd be stupid to waste good money on silly things like testing that won't increase their sales.

      Or, as others here keep pointing out, Microsoft's only "responsibility" is to its shareholders. Their ongoing success has hugely rewarded their shareholders. They are obviously Doing It Right. They have no other responsibilities.

      If there are signs that this fuss has a lasting effect on their profitability, they'll do something about it. But it'll probably die off in a short time, and only a few geeks (non-customers) will remember it. How many people can name even one piece of software that died on Jan 1, 2000? Customers won't remember this one, either. Most of them will never even hear about it. So Microsoft's management isn't worried about it.

      And anyway, the problem is "fixed" now (for another 3.99 years). So why even bother discussing it?

      (What, me cynical? ;-)

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    21. Re:Import calendar? by lewiscr · · Score: 2, Informative

      I'm also curious as to why 1980 is the epoch, but that's not as important.

      MS-DOS defines the epoch as Jan 1, 1980.

    22. Re:Import calendar? by Anonymous Coward · · Score: 0

      >I'm also curious as to why 1980 is the epoch

      (Not-so) Interesting fact:

      The Unix universe uses 1970 as their epoch.

      DOS (and the FAT series of filesystems) use 1980.

      Because most of the software that comes out of Redmond is based in 16-bit code that was based on 8-bit code that was based on 4-bit code, even to this very day, you get odd legacy quirks like this.

      It's not really a problem, per se, since no *accurate* date will be anywhere near 1980 given the sale dates of the first Zunes; there's no reason that you need the system to keep track of dates that predate that system unless it's specially built to do that. 1970 is no less strange a date than 1980. But that's your reason anyway.

    23. Re:Import calendar? by Hal_Porter · · Score: 1

      All those are either GPL or LGPL.

      If you use a GPL licensed C library then everything you link to it would be covered by the GPL. Even an LGPL'd library is problematic e.g.

      http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License#Differences_from_the_GPL
      The main difference between the GPL and the LGPL is that the latter can be linked to (in the case of a library, 'used by') a non-(L)GPLed program, which may be free software or proprietary software.[1] This non-(L)GPLed program can then be distributed under any chosen terms if it is not a derivative work. If it is a derivative work, then the terms must allow "modification for the customer's own use and reverse engineering for debugging such modifications." Whether a work that uses an LGPL program is a derivative work or not is a legal issue. A standalone executable that dynamically links to a library is generally accepted as not being a derivative work. It would be considered a "work that uses the library" and paragraph 5 of the LGPL applies.
      A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.

      Essentially, it must be possible for the software to be linked with a newer version of the LGPL-covered program. The most commonly used method for doing so is to use "a suitable shared library mechanism for linking". Alternatively, a statically linked library is allowed if either source code or linkable object files are provided.

      One feature of the LGPL is that one can convert any LGPLed piece of software into a GPLed piece of software (section 3 of the license). This feature is useful for direct reuse of LGPLed code in GPLed libraries and applications, or if one wants to create a version of the code that software companies cannot use in proprietary software products.

      There are two issues here - whether your embedded system image consisting of your code and the LGPL code is a "derivative work" and how you plan to allow end users to update the library.

      Basically using this sort of code in an embedded system where you don't have the rights to release all of the source code is a bit unwise.

      --
      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;
    24. Re:Import calendar? by Anonymous Coward · · Score: 0

      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?

      Well, Microsoft did exactly that and look where it got them.

    25. Re:Import calendar? by Anonymous Coward · · Score: 0

      Way to argue the wrong issue...

    26. Re:Import calendar? by OolimPhon · · Score: 1

      They certainly are still liable for all the busted Zunes, but I couldn't imagine Microsoft didn't have *some* C leap-year code sitting around that actually worked, and could be compiled for any chip they wanted.

      [citation needed]

    27. Re:Import calendar? by Anonymous Coward · · Score: 0

      "I can't remember the last time anyone wrote their own Leap Year calendaring"

      This is me raising my hand.

      Special purpose RF modem with time/date feature added at the last hour. 8k of flash, assembly language, MC9S08GT8. Where's the library for that?

    28. Re:Import calendar? by Plunky · · Score: 1

      All those are either GPL or LGPL.

      Open your mind. Try libc. No taint and truly, you're welcome.

    29. Re:Import calendar? by Anonymous Coward · · Score: 0

      Exactly! The real bug here is not using a library function to do a common operation.

    30. Re:Import calendar? by sam0737 · · Score: 1

      Yes as mentioned by the summary, this is a driver - a driver! Don't expect standard C library is there.

      Further more, the functions seems to be converting treating 1980 as epoch...

    31. Re:Import calendar? by Anonymous Coward · · Score: 0

      People used 1980 as the epoch because that is what DOS defined.

      mov ah, 2Ah;
      int 21h;

      The result of this assembly code was several values placed in 8-bit registers. The year was a signed value based on 1980.

    32. Re:Import calendar? by greed · · Score: 1

      I don't know, the only testplans I've been involved with that involved leap-year code DID have "is day 366 reported as December 31" kind of things, along with Feb 28, 29, Mar 1, and so on.

    33. Re:Import calendar? by Anonymous Coward · · Score: 0

      Quite so.

      Windows 3.11, 95, 98, ME all provided broken software.
      XP and Vista were also pretty broken at launch till "Service Packs" fixed stability, and that is still not addressing a possibly broken security model.
      How many people jumped ship to Linux, or Mac?

      The original XBox 360 suffered hardware failures (RRoD and Disk cutting), yet people push it as "superior" to other platforms.

      About the only thing I haven't seen pushed is MSCE which most people see as "not quite there" even when they have to use it.

    34. Re:Import calendar? by SnarfQuest · · Score: 1

      How many people can name even one piece of software that died on Jan 1, 2000?

      Sorry, but I missed that day, because all the nuclear bombs detonated and killed almost everyone. The planes falling from the sky, the runaway cars, and mass starvation killed the rest.

      --
      Who would win this election: Andrew Weiner vs Andrew Weiner's weiner.
    35. Re:Import calendar? by Anonymous Coward · · Score: 0

      I can't remember the last time a QA department was asked to test date functions.

      Y2K?

      2005 when a leap second was arbitrarily added?

      2008 change in DST in the USA and Canada?

      Dec. 31, 2008 when another leap second was arbitrarily added?

    36. Re:Import calendar? by Anonymous Coward · · Score: 0

      Now each day has 24 hours.

      Well... mostly.

      Sometimes there are 23 hours and sometimes there are 25 hours. (See DST)

      And sometimes, like 2008 December 31, there are 24 hours 1 second.

    37. Re:Import calendar? by TrekkieGod · · Score: 1

      MS-DOS defines the epoch as Jan 1, 1980.

      That explains it. Thanks.

      --

      Warning: Opinions known to be heavily biased.

  7. "Leaked"...? by Anonymous Coward · · Score: 5, Informative

    It's an open source driver from Freescale.

    1. Re:"Leaked"...? by mrphoton · · Score: 0

      year "leaked". Who's job is worth leaking a driver for a dumb microsoft player. Do we know how this ended up on the net? It strikes me as a bit odd? Also has anybody else noticed that the source code seems to be nicely written (bar the bug)..... somewhat surprising for microsoft I allways assumed there code was written by a bunch of children.

    2. Re:"Leaked"...? by Anonymous Coward · · Score: 0

      Clearly, the code was poorly written because it had an infinite loop in a case with non-pathological inputs.

    3. Re:"Leaked"...? by Anonymous Coward · · Score: 4, Informative

      Who's job is worth leaking a driver for a dumb microsoft player.

      The code is not specific to the Zune. It is specific to the MC13783 PMIC RTC that is used in many different pieces of hardware.

      Do we know how this ended up on the net?

      The authors (Freescale Semiconductor, Inc.) released the source under the terms of the GPL.

      Also has anybody else noticed that the source code seems to be nicely written (bar the bug)..... somewhat surprising for microsoft I allways assumed there code was written by a bunch of children.

      Microsoft didn't write the code. It was written by Freescale Semiconductor, Inc.

    4. Re:"Leaked"...? by vcompiler · · Score: 1

      If the driver code is licensed under GPL, should the whole OS kernel of Zune be licensed under GPL enforcedly?

  8. Re:Old by Anonymous Coward · · Score: 0

    You know there's a problem when Digg covers this technology news before Slashdot.

  9. Re:Old by LostCluster · · Score: 3, Interesting

    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.

  10. Why write any date/time code? by chafey · · Score: 1

    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.

    1. Re:Why write any date/time code? by p0tat03 · · Score: 5, Informative

      This was written by the Freescale guys, not MS, where it would make sense for the device manufacturer to ship their own date/time code.

    2. Re:Why write any date/time code? by cbhacking · · Score: 3, Insightful

      Ah, thank you. This explains better why the 2nd-gen and 3rd-gen Zunes didn't suffer this problem; they were completely designed and developed in-house.

      --
      There's no place I could be, since I've found Serenity...
    3. Re:Why write any date/time code? by clive_p · · Score: 1

      My first reaction was to ask why a simple media player needed to know the date and time? Can anyone explain this?

  11. QA team slacking off... by feepness · · Score: 4, Funny

    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.

    1. Re:QA team slacking off... by KiltedKnight · · Score: 1

      You proceed from a false assumption... that Microsoft ever really had a QA team in the first place.

      --
      OCO is Loco
    2. Re:QA team slacking off... by Anonymous Coward · · Score: 0

      My first reaction from looking at the code is that it's the development (coding) team's responsibility to test for these type of bugs, more so than QA.

      But the bug is in Freescale's driver, so the lines of responsibility become blurred. Freescale's coders should have caught that bug in unit testing, but MS should've had controls in place too.

    3. Re:QA team slacking off... by moosesocks · · Score: 1

      Microsoft Bob drove the entire QA team to insanity.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    4. Re:QA team slacking off... by trolltalk.com · · Score: 2, Funny

      "You proceed from a false assumption... that Microsoft ever really had a QA team in the first place."

      They do - it's called "customers."

  12. QA?? by Gorimek · · Score: 2, Interesting

    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)

    1. Re:QA?? by Anonymous Coward · · Score: 0

      That's an unrealistic and naive approach to development. Bugs happen, regardless of the methodologies put into place.

      The larger the project, the more limiting and unrealistic TDD becomes. How's a project with a couple of million lines of code supposed to be put through TDD? It won't.

    2. Re:QA?? by Anonymous Coward · · Score: 0

      Not really. The bug is a simple algothrimical problem, if you're writing an algoritm you should be able to prove it's functionality by writing some fairly straightforward unit tests

    3. Re:QA?? by Anonymous Coward · · Score: 0

      Test Driven Development assumes it's possible to write a test for every possible condition. That is flat out impossible because as a project grows in size the test tree grows exponentially. Eventually it becomes like trying to test for every possible move in Chess or Go expect multiplied many times.

      Currently proper TDD just impossible even if it were possible to make an automated system, let alone doing it "by hand" with code monkeys writing tests.

    4. Re:QA?? by Anonymous Coward · · Score: 0

      Nobody, but nobody is claiming that TDD catches every single possible bug. But done properly, it's extremely useful, and it does a great job of preventing regressions.

    5. Re:QA?? by thermian · · Score: 1

      While it is possible to test what you might term 'worker' methods that manipulate data in easy to test terms, like adding, deleting, transforming and such, its really quite hard to use TDD when developing software for whom neither the exact, nor even the ideal outcome is known in advance.

      I speak of things like GAs and such. Sooner or later there will be a need for large blocks of very complex code which can't easily be broken up so you can run a test and say 'that' bit is broken.

      I use unit for some things, but I would not consider using it for an entire application unless that application were really simple.

      --
      A learning experience is one of those things that say, 'You know that thing you just did? Don't do that.' - D. Adams
    6. Re:QA?? by Anonymous Coward · · Score: 0

      Suppose Freescale and/or Microsoft had used TDD for this particular piece of code. To avoid falling in the trap of using the same algorithm to test the module being tested, they probably would have written the unit test to check that the correct result was obtained for an array of specific dates (let's say 30), including leap year dates such 29-Feb-2008 and 4-July-2004 and "boundary cases" like 1-Jan-1980, 31-Dec-2010, etc.

      TDD would only have caught this if the developer had had the foresight to include 31-Dec-2008 in the test.

    7. Re:QA?? by Gorimek · · Score: 1

      I agree that TDD works differently well for different types of problems. This kind of pure algorithmic function is where it works the best. It's so much faster and higher quality than the thinking way.

      I made no claims about TDD in general in the original post, and should perhaps leave it at that. But I'd be very hesitant to bet my livelihood on any complex code that I couldn't know if it worked or not. Sure, some things can't easily be broken into testable components. Sometimes software engineering requires hard work, but it is often worth the effort.

    8. Re:QA?? by thermian · · Score: 1

      But I'd be very hesitant to bet my livelihood on any complex code that I couldn't know if it worked or not.

      The don't try and be a scientist :)
        I have spent years writing code when I had no idea whether what I was writing was going to produce valid, useful results, or digital donkeypoop.

      It is pretty stressful at times, but the results when things go well can be amazing (we don't talk about the poop..). Still, I must admit it would be nice sometimes to write nice simple applications that can be fully specified in advance.

      --
      A learning experience is one of those things that say, 'You know that thing you just did? Don't do that.' - D. Adams
    9. Re:QA?? by Anonymous Coward · · Score: 0

      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)

      No offense to TDD which is a perfectly good design approach but this is the same argument for requirement driven development which must have a test case for each requirement (not always 1 to 1).

    10. Re:QA?? by ceoyoyo · · Score: 1

      Perhaps if they'd asked why their mp3 player needs to critically depend on the exact time in the first place, they wouldn't have had the crash at all, tests or no tests.

    11. Re:QA?? by Anonymous Coward · · Score: 0

      This kind of bug is where formal code reviews shine. More than likely a TDD style would not have resulted in a test for this edge case, since the developer didn't think of it in the first case. But more eyes would definitely have caught this obvious bug.

    12. Re:QA?? by Anonymous Coward · · Score: 0

      TDD is a retarded name. With TDD, tests drive the development, but what drives the tests? Requirements drive the tests. So if requirements drive tests, and tests drive development, isn't is really "requirements driven development"?

      Oh wait, isn't requirements driven development just plain old proper engineering, which has was established oh ... 75 years ago? TDD and agile are just non-engineers "discovering" the discipline of engineering.

  13. Bigger bugs have gotten through on Windows CE by msgmonkey · · Score: 5, Interesting

    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.

    1. Re:Bigger bugs have gotten through on Windows CE by Anonymous Coward · · Score: 2, Insightful

      If you dealt with Platform Builder you could see the WindowsCE source code. There were some amazing bugs in there. One that is more relevant that i saw in WindowsCE 4.x was the daylight savings changeover code.

      They had a function that returned whether or not time needed to be added for daylight savings. The function would have a list of changeover times for various regions. If the time was past the first changeover time of the year the function would add time, if the function was past the second changeover time in the year the function would remove time.

      The end result was the product shipped with time that was incorrect for the entire Southern Hemisphere.

    2. Re:Bigger bugs have gotten through on Windows CE by Anonymous Coward · · Score: 0

      This bug still exists in CE 5. I've encountered it on Windows Mobile 5 and 6 devices. Based on my experience writing apps for these devices, the whole CE/WinMo QA group should be the first to go in the upcoming round of Microsoft layoffs.

    3. Re:Bigger bugs have gotten through on Windows CE by thewiz · · Score: 1

      Hey, don't be so hard on the Microsoft programmers; they are, after all, only human.
      Zuner or later this was bound to happen.

      --
      If "disco" means "I learn" in Latin, does "discothèque" mean "I learn technology"?
    4. Re:Bigger bugs have gotten through on Windows CE by Anonymous Coward · · Score: 0
  14. That code is real bad code! by canuck57 · · Score: 2, Insightful

    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;

    1. Re:That code is real bad code! by colfer · · Score: 1

      Those lines are correct. The function takes days=number of days since 1980, and calculates year/month/day, as well as the day of the week.

    2. Re:That code is real bad code! by cbhacking · · Score: 1

      Why do those particular lines strike you as so especially terrible? It's part of an iterative function that takes a number of days since a defined starting point (Jan 1 1980, inclusive, IIRC) and determines how many years (and the remainder number of days) have elapsed. The comments made that fairly clear to me.

      --
      There's no place I could be, since I've found Serenity...
    3. Re:That code is real bad code! by Anonymous Coward · · Score: 0

      Because this code is _in_the_os_, it was provided by the CPU manufacturer for an embedded component. If anyone tried to put a call to asctime in this code, I would have them hung drawn and quartered because it would have killed performance.

      Damn, performing string operations in driver code on an mp3 player.

      Even worse, assuming that the C library is present and conforming.

      wow, just wow.

    4. Re:That code is real bad code! by Anonymous Coward · · Score: 1, Funny

      If I was your manager, I would fire you for being stupid.

    5. Re:That code is real bad code! by Anonymous Coward · · Score: 0

      Why not use asctime() and rely on it's more proven calculations of leap year and the like via the OS libraries?
      Because the Windows CE C runtime is woefully under-featured and it's support of Win32 time functions is very limited.

    6. Re:That code is real bad code! by Anonymous Coward · · Score: 0

      "hanged" it's "hanged"

      when a person is "hung" it's something different entirely.

    7. Re:That code is real bad code! by shess · · Score: 1

      What jumps out at me is that the loop is counting 'day' backward and 'year' forward. Far better would be to have a pair of forward-counting values, which you compare with your target. That small change totally changes the character of the loop.

    8. Re:That code is real bad code! by Anonymous Coward · · Score: 0

      I said hung, I meant hung in my closet like a shirt, drawn like a sketch and then quartered like an apple.

      I meant what I said, and said what I meant dammit!

    9. Re:That code is real bad code! by Anonymous Coward · · Score: 0

      What on earth are you talking about? You start with just days which you want to convert in years. This implies decreasing days, increasing years.

  15. Regardless of whatever code in it is faulty by scourfish · · Score: 5, Funny

    Lines 122, 521, 690, 710, and 748 scare me; gotos in C code...

    1. Re:Regardless of whatever code in it is faulty by KiltedKnight · · Score: 3, Insightful
      Ever written code for an OS or device driver? You use them there... frequently... as "get me the frack out of here because of a fatal error"...

      Never mind that if done properly, there is nothing wrong with using a goto statement... just make sure that you only move in one direction... ideally "down" towards the end of the function, not somewhere else in the whole program.

      --
      OCO is Loco
    2. Re:Regardless of whatever code in it is faulty by concernedadmin · · Score: 5, Interesting

      Lines 122, 521, 690, 710, and 748 scare me; gotos in C code...

      They've used one form of a goto that's actually quite readable and useful. Would you rather have:

      if (condition1 && condition2) {
      /* boilerplate code with a return */
      }

      if (issue1 || issue2) {
      /* same repeated boilerplate code with a return */
      }

      or

      if (condition1 && condition2) {
      goto cleanup;
      }

      if (issue1 || issue2) {
      goto cleanup;
      }
      cleanup:
      /* just one instance of this code,
      no need for duplication of efforts */
      Believe it or not, there are useful reasons to use goto, and Microsoft happened to use goto for the right reason here. The Linux kernel also happens to use this practice to boost the readability of the code.

    3. Re:Regardless of whatever code in it is faulty by jd142 · · Score: 2, Insightful

      Why not this:

      function cleanup():void
      { //do something
      }

      if (condition1 && condition2) {
      cleanup();
      }

      if (issue1 || issue2) {
      cleanup();
      }

      If something is done exactly the same way twice, that's a function. Heck, if something is sufficiently complicated that it makes the main code easier to read, that's a function too in my book.

      Of course, I prefer my braces to line up vertically, so what do I know?

    4. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Sheesh, a long time ago someone noticed all the crappy code being written with goto and globals (or whatever) and wrote a paper about it. Now every moron developer thinks it's always bad to use them in every case. I see people (especially younger developers) with this attitude all the time. They see some code and freak out about how bad it is and how the programmer didn't know what they were doing because it has a global variable or something. It's funny because they are the one that is clueless.

      They can be used effectively and are often required for a good proper design. A skilled programmer would recognize this.

    5. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      What do you do if you have 10 variables allocated locally in the function? Pass them all to the cleanup function?

    6. Re:Regardless of whatever code in it is faulty by AuMatar · · Score: 4, Informative

      Because cleanup doesn't have access to the local variables of the calling function. This means they need to be passed in. The result is a very obscure function that takes in half a dozen or more variables and gets difficult to maintain since it's purpose makes absolutely no sense without the context in the calling function (not to mention easy to have bugs- forget to check just one pointer for null before using it and you're into undefined behavior, which may only occur in rare error conditions making it difficult to test for). Using a cleanup function like that just isn't practical.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    7. Re:Regardless of whatever code in it is faulty by cbhacking · · Score: 1

      Mostly that's a matter of the way cleanup frequently involves local variables. Sure, you could pass them all in by reference (since this is C, that would mean passing them as
      cleanup(&local1, &local2 &local3);
      but it gets quite messy, both in the function declaration and in all the calls.

      --
      There's no place I could be, since I've found Serenity...
    8. Re:Regardless of whatever code in it is faulty by Billly+Gates · · Score: 0

      But why use it you do not have too?

      Computer science books and even my highschool basic programming class mentioned its not proper programming to use a GOTO. Is there any computer science professor that supports GOTO statements in programs?

      Not every programmer is good and a good programmer will refrain from making the program harder to read or more difficult to debug when jr programmers modify it later.

      GOTOs by their very nature encourage bad programming as much as pointers do.

    9. Re:Regardless of whatever code in it is faulty by Todd+Knarr · · Score: 1

      Actually there are good times to use GOTO. Finite state machines, for instance. The code's much easier to read if you use GOTOs to handle the transitions, trying to do it using only "structured code" constructs results in an unintelligible mass of spaghetti. Error handling's another case, it's much easier to parse a single GOTO to the exit code than the mass of nested conditionals needed to correctly handle erroring out of multiple nested loops and conditionals without using GOTO.

      The key is knowing when GOTO makes the code simpler to read. Note that more compact != simpler.

    10. Re:Regardless of whatever code in it is faulty by TrekkieGod · · Score: 1

      They've used one form of a goto that's actually quite readable and useful. Would you rather have:

      Neither. I'd rather throw an exception and perform the cleanup when catching said exception.

      --

      Warning: Opinions known to be heavily biased.

    11. Re:Regardless of whatever code in it is faulty by Beve+Jates · · Score: 1

      There are many times when a goto makes sense. Handling exceptional conditions in a very popular one in C. It is by far one of the cleanest ways to emulate exceptions in C. It can be done other ways but goto is often easiest to understand and requires very little code.

      Take a look at any kernel source code and you will find lots of goto's. Actually, pretty much any nontrivial C source base probably has at least a few goto's in there somewhere. Goto is a powerful feature of C, it can be abused but it's also very useful.

    12. Re:Regardless of whatever code in it is faulty by QRDeNameland · · Score: 4, Interesting

      The addition of single bool avoids both the specialized cleanup() function and the goto:

      bool needs_cleanup = false;

      if (condition1 && condition2) {

      needs_cleanup = true;

      }

      if (issue1 || issue2) {

      needs_cleanup = true;

      }

      if (needs_cleanup) {

      // clean up local vars exactly as you would have done

      // have done under the cleanup: label with the goto

      }

      --
      Momentarily, the need for the construction of new light will no longer exist.
    13. Re:Regardless of whatever code in it is faulty by 1729 · · Score: 2, Informative

      But why use it you do not have too?

      Computer science books and even my highschool basic programming class mentioned its not proper programming to use a GOTO. Is there any computer science professor that supports GOTO statements in programs?

      GOTOs are not inherently bad. At some level, they're unavoidable. (Have you ever programmed in assembly language?)

      As for CS professors, Donald Knuth uses and defends GOTO statements:

      http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf

      (His code comments often make reference to why he uses GOTOS. For example, in his implementation of the classic Adventure game, he writes: "By the way, if you don't like |goto| statements, don't read this. (And don't read any other programs that simulate multistate systems.)" In http://www-cs-faculty.stanford.edu/~knuth/programs/15puzzle-korf1.w, he writes: "as a full professor with tenure, I don't have to worry about being fired when I use |goto| statements.")

      Not every programmer is good and a good programmer will refrain from making the program harder to read or more difficult to debug when jr programmers modify it later.

      GOTOs by their very nature encourage bad programming as much as pointers do.

      Pointers encourage bad programming? No offense, but do you have any real programming experience beyond your "highschool basic programming class"?

    14. Re:Regardless of whatever code in it is faulty by AuMatar · · Score: 1, Redundant

      Not really. Normally the code is structured like this:

      if(condition){
          goto cleanup;
      }
      do_something_that_is_only_valid_if_not_condition;
      if(condition2){
          goto cleanup;
      }
      do_something_that_requires_not_condition2; ...
      cleanup:
      do_cleanup;

      You *could* get it to work your way, with a lot of restructuring. You'd end up with 5 or 6 deep nested if statements though. You get to choose what way you think is least ugly. Generally, the goto is actually the best of several bad options. You're going to have something ugly, but the goto is fairly maintainable and makes the main body of code the least ugly it can be.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    15. Re:Regardless of whatever code in it is faulty by petermgreen · · Score: 1

      That assumes you are programming in an environment where you have that luxury.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    16. Re:Regardless of whatever code in it is faulty by TrekkieGod · · Score: 1

      You can implement something that behaves like an exception in C rather simply.

      --

      Warning: Opinions known to be heavily biased.

    17. Re:Regardless of whatever code in it is faulty by Blakey+Rat · · Score: 2, Insightful

      Ok, so I have a loop within a loop, and I need to drop out of BOTH loops because of some error condition in the inner loop:

      for( x = 0; x 10000; x++ )
      {
          for( y = 0; y 100; y++ )
          {
              if( error_condition ) goto fatal_error;
          }
      }

      fatal_error:
      CleanupAndQuit();

      The only alternative is to create a boolean flag and check it each go through the loop, but that's retarded. And note that, even Javascript, which is an modern language designed with all the lessons learned from C, also has a way to break to a specific label, added exactly because it lacked a GOTO.

    18. Re:Regardless of whatever code in it is faulty by jc42 · · Score: 1

      [E]ven Javascript, which is an modern language designed with all the lessons learned from C, also has a way to break to a specific label, added exactly because it lacked a GOTO.

      In other words, they learned that goto commands are fine if they're spelled differently. The objection is to the four letters "GOTO", not to the language construct. Sorta like the Jewish objections to the sequence of four letters transliterated as "YHWH". So they replace that name by a name that's spelled differently, and it's all OK.

      The objection to GOTOs really is a kind of religious commandment (handed down by the Prophet Dijkstra), and it's every bit as logical as most religious commandments.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    19. Re:Regardless of whatever code in it is faulty by codegen · · Score: 1
      Goto skips the code between it and the label:

      bool needs_cleanup = false;

      if (condition1 && condition2) {

      needs_cleanup = true;

      }

      if (not needs_cleanup){

      if (issue1 || issue2) {

      needs_cleanup = true;

      }

      if (not needs_cleanup){

      }

      }

      if (needs_cleanup) {

      // clean up local vars exactly as you would have done

      // have done under the cleanup: label with the goto

      }

      --
      Atlas stands on the earth and carries the celestial sphere on his shoulders.
    20. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Incorrect.

      The assumption here is that the code needs to avoid executing any additional functionality in the event of an error (aside from the clean-up code, of course).

      In order to achieve this with a just boolean flag you would have to litter your code with if(!needs_cleanup) checks - especially if things can fail at multiple points in the function.

      That's just horrible.

      Using goto in this case is far simpler and more elegant.

    21. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      so is this guy a troll, or is he really this stupid? pointers encourage bad programming?

    22. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      nope, that flag is not a replacement for goto. Read concernedadmins post again, carefully and you'll see how his code snippet is different from your 'fix'.

      the use of goto in the kernel or in drivers in such scenarios is to BAIL. In that example if condition1 fails, you should not even be executing issue1 and issue2. goto takes execution straight to the end of the function in your case you are setting a failure flag, but continuing to execute the rest of the code and thats wrong.

    23. Re:Regardless of whatever code in it is faulty by moderatorrater · · Score: 1

      Looks like it's time for me to jump into an argument I shouldn't be jumping into... bool goto_cleanup = false; if(condition){ goto_cleanup = true; } else { do_something_that_is_only_valid_if_not_condition; } if(condition2){ goto_cleanup = true; } else { do_something_that_requires_not_condition2; ... } if(goto_cleanup) { do_cleanup } My guess is that you're a relatively smart dude who's worked on code with people who've been taught that it's better to murder puppies than use goto's, so goto's really are the proper solution in the cases you use them in. However, they're also capable of extremely unreadable code, so the vilification is probably justified.

    24. Re:Regardless of whatever code in it is faulty by ceoyoyo · · Score: 1

      Exactly what do you think your fancy loops and other flow control compiles to? Assembly with jumps. Jumps are gotos.

      Many programmers today can't find their way around assembly and so they shouldn't be allowed to use gotos either. Of course, current wisdom seems to be going towards not allowing programmers to use pointers either. So your textbooks are probably sort of correct, but not in all cases. Particularly not for embedded software

    25. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Negative, as it'll still run through code before cleanup, where a goto goes directly to the label.

      The addition of single bool avoids both the specialized cleanup() function and the goto:

      bool needs_cleanup = false;

      if (condition1 && condition2) {

      needs_cleanup = true;

      }

      if (issue1 || issue2) {

      needs_cleanup = true;

      }

      if (needs_cleanup) {

      // clean up local vars exactly as you would have done

      // have done under the cleanup: label with the goto

      }

    26. Re:Regardless of whatever code in it is faulty by weicco · · Score: 2, Insightful

      This is the structure I used when I was writing stuff in C some ten years ago.

      do {
              if (condition1)
                      break;
              do_something();

              if (condition2)
                      break;
              do_something_else();
      }
      while(0);

      cleanup();

      --
      You don't know what you don't know.
    27. Re:Regardless of whatever code in it is faulty by AuMatar · · Score: 1

      Slashdot screwed up the formatting , but it looks like you just want to move everything into deeper and deeper elses. That's doable, but the longer your function is the harder and harder it is to read. A simple function that reads from an entire file of unknown size would need at least 4 levels of elses- one for stat to get the file size, one for the buffer allocation, one for the fopen, one for the fread (I'm assuming you can ignore errors from fclose). Do something with the data and it gets worse. It's not hard to get into such situations.

      There's times to use each method. Elses are good if it is only 2 or 3 levels, beyond that it's just unreadable. Gotos can create unreadable code, but a single label used for cleanup before a return call isn't too bad. No worse that a C++/Java exception- in fact in those languages this would probably be handled by exceptions. Sometimes all you get to do is choose which type of ugliest is least annoying. This is probably the most common use of goto's in production code, it's generally the accepted solution.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    28. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Not quite. You still have to explicitly avoid any code between the second if and the cleanup. This either requires encapsulating it into another if (which in turn makes you indent the whole block and so on) or -- you guessed it -- use a goto.

    29. Re:Regardless of whatever code in it is faulty by 7+digits · · Score: 1

      That is actually an obfuscated goto. And it is difficult to use if you have a loop in your code, because C can't break from inner loops to outer loops.

      There is no good solutions for this in C. Personally I go with:

      if (condition1_opposite)
      {
          do_something();
          if (condition2_opposite)
              do_something_else();
      }
      cleanup();

      But it depends on the complexity of the various parts. I could also very well end up writing it like:

      do_stuff( stuff );
      cleanup();

      with:

      do_stuff( stuff )
      {
          if (condition1) return;
          do_something();
          if (condition2) return;
          do_something_else();
      }

      depending on:
      * the likelihood of adding additional conditions, additional do_something()
      * the amount of stuff passed around
      * the semantic of the conditions (are those stuff we are looking for [better to go with solution 1], or corner cases that should be avoided [better go with solution 2])

    30. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      You got it completely backwards. The cleanup at the end of the function always needs to be done. It's the steps in between that need to be skipped if the previous step failed.

    31. Re:Regardless of whatever code in it is faulty by dkf · · Score: 2, Interesting

      The addition of single bool avoids both the specialized cleanup() function and the goto:

      [...]

      The problem with that is that it tends (in real code) to either greatly increase the depth of nesting of the code (making it harder to understand) or, worse yet, spray a great collection of various flags indicating the various types of cleanup required and what conditions have and haven't been checked. Making conditions more complex isn't a good plan at all for maintenance, since it increases the difference between the pseudo-code for the function (i.e. the level that you think about, without all the grotty code for handling failure modes and obscure cases) and the real code...

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    32. Re:Regardless of whatever code in it is faulty by dkf · · Score: 1

      The objection to GOTOs really is a kind of religious commandment (handed down by the Prophet Dijkstra), and it's every bit as logical as most religious commandments.

      Mod parent up; he's nailed exactly what's going on.

      I should note that what Dijkstra was really complaining about originally was using GOTOs for things that are really basic structured programming constructs: building your own WHILE with GOTO is (almost) always a bad idea. But then he was railing about it back in the days of FORTRAN and PL/1, so what do you expect...

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    33. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      The goto statement is there because it is useful for good reasons. For example, whenever you want to write your own state machines then you have to needlessly bend over backwards to avoid using goto statements. By avoiding goto statements simply due to religious reasons you end up forcing the use of unreadable messes like a bunch of nested if() statements or relying on compound loops that iterate through a hand full of variables.

      So in essence you are avoiding goto statements due to irrational reasons and instead you are implementing points of failure and less-efficient code, simply because you can't use your brain to think for yourself and you keep blabbering the "gotos are bad" mantra.

    34. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      At the same time, though, it doesn't GAIN you anything. Contrary to what some people (Dijkstra) may say, gotos aren't inherently bad; they're a tool, and like any tool, they can be misused and misapplied, but they do have their uses.

      In fact, your above code is worse than the goto-based version - only slightly so, but still worse, because someone reading yours would not necessarily have an idea what "needs_cleanup = true" actually means in the end, whereas "goto cleanup" is clear. The former is just a description of an attribute the current state possesses - it needs cleanup -, but the latter actually DOES something: it not only tells you cleanup is necessary, but in fact CLEANS UP RIGHT THEN.

      I'll grant you it's not a huge difference, but it still seems silly to me to avoid perfectly good code just for a religious, irrational despise of gotos, just because some authority figure said so.

    35. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Only in this simplified version. If there are other side-effects inside the second 'if' condition that should only be executed only if condition1 or condition were false, you would have to test for that also.

      If that were not the case, one could simply merge the two 'if' statements into one and do clean-up there right there if it evalutes to true, and so skip both goto, function-calls, and extra variables :)

    36. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Yeah, but at least to me it is usually less readable than the goto variant. "goto" isn't bad for some magical reason: It is bad when it is abused because it makes code hard to read. When goto makes code easier to read, then goto is the appropriate choice.

    37. Re:Regardless of whatever code in it is faulty by Gazzonyx · · Score: 1

      And it makes tracing failure paths all that much more painful... each one is calling a generic function and now you're grepping through gobs of meta-data to even know the context of what you're looking at. Then you forget whom the caller was, trace back up, and find out that you've got recursive errors! Also, the overhead for constructing and tearing down frames every other call isn't exactly sexy; if you're crashing, at the very least, do it at a reasonable speed.

      --

      If I mod you up, it doesn't necessarily mean I agree with what you've said, sorry.

    38. Re:Regardless of whatever code in it is faulty by weicco · · Score: 1

      You are correct, it doesn't work well with loops. I don't think gotos are bad but let me clear up this a bit.

      When I was doing C stuff, I wrote device drivers for Windows 9x/NT/CE. I took this approach that I split my code to tiny little functions and trusted that the compiler would inline them if appropriate. So I tried to isolate all those nasty loops to sub-functions though this was not always possible. This allowed me to efficiently test those tiny functions. Well, I think this is clear to all (or at least should be) so enough with the blathering...

      I ended up, in my opinion of course, with some nice looking code and I could avoid goto-clauses which were considered bad amongst our most purist coders. This approach also tidied up the cleanup code which I also split inside those sub-functions. It would have really been pain in the ass otherwise.

      So actually the code was something like this:

      int do_some_loopy_loop() {
              int retval = 0;
              while (...) {
                      if (!ok) {
                              retval = -1;
                              break;
                      }
              } /* Clean up local stuff */

              return retval;
      }

      void initialize_em_all() {
              while (0) {
                      if (do_some_loopy_loop() 0) { /* If there's something special to cleanup do it here.

                                    We could use goto here but that would piss
                                    off rest of the coders.

                                    In the end it doesn't really matter. */
                              break;
                      }
              } /* Clean up local stuff */
      }

      Weird. Slashdot doesn't like my C-style comments :(

      --
      You don't know what you don't know.
    39. Re:Regardless of whatever code in it is faulty by Billly+Gates · · Score: 1

      Assembly is bad which is the point of using a higher level language. Assembly should be avoided as well which is why you microkernels are the most stable.

      Today's computers have tens and sometimes hundreds of services or processes running and a single program that uses direct memory access with a pointer can cause a GP fault and bring it down. I remember the days of Windows 3.1 and having to hit the reset button.

      Csharp and Java provide access to pointers indirectly through their apis so they are managed. Goto statements make spaghetti code and makes debugging hard. You only found one professor who uses them. Pointers also cause memory leaks in programs and other errors that can be avoided by calling by value or using an api which manages the pointers indirectly.

    40. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      I think there was some implied code in that function, in which case your solution would not work.

      if(foo) goto cleanup;
      bar();
      if(horse) goto cleanup;
      apple();
      cleanup:
      baz();

    41. Re:Regardless of whatever code in it is faulty by brkello · · Score: 1

      Uh no...you don't get it at all. The issue is that something bad has happened and you want to get out of the function, but need to do some cleanup first. You know things are fubar, so you don't want to do any more operations so you don't screw things up worse. You could check if needs_cleanup is true in all your conditional statements after where needs_cleanup could first be set. But that is less clear and more prone to bugs than using goto appropriately.

      --
      Support a great indie game: http://www.abaddon360.com
    42. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      In such a case you can write:
      if (condition1 && condition2)
          cleanup(...);

      if (issue1 || issue2)
          cleanup(...);

      And define a function
      void cleanup(...)
      { /* mess around */
      }

      However even simpler code would be:
      if ((condition1 && condition2) || issue1 || issue2) { /* do the cleanup here */
      }

    43. Re:Regardless of whatever code in it is faulty by Just+Some+Guy · · Score: 1

      Making conditions more complex isn't a good plan at all for maintenance, since it increases the difference between the pseudo-code for the function (i.e. the level that you think about, without all the grotty code for handling failure modes and obscure cases) and the real code...

      Not to mention the performance penalties. Since this stuff is typically inside driver code, if there's an exit condition, you want to quit quickly. You don't want to test for if(!needscleanup) 200 times before the exit handler is reached.

      --
      Dewey, what part of this looks like authorities should be involved?
    44. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      you mean.....

      if (!needs_cleanup && (issue1 || issue2))

    45. Re:Regardless of whatever code in it is faulty by QRDeNameland · · Score: 1

      Actually, I was looking more at the first guy's rewrite than the original, and you're right that I'm not bypassing the second check which a goto would. And you are correct that the restructuring could get uglier as complexity increases, although a second bool to determine whether to continue checking further conditions could avoid complex nesting. (I've found that technique useful in edit situations where you may or may not want to keep checking for additional error conditions based on the seriousness of a given error.)

      And although, as a poster downstream suggested, I was always taught to avoid gotos in C/C++ like the plague, I do agree that the example in the original code is actually a good example where a goto can indeed be useful.

      However, my broader point is that it is generally not too horrendously difficult to get around a goto in C/C++, and more often than not IME, developers who claim they "had to" use the goto could have just as easily and just as readably (if not moreso) done it another way. I'd say the rule of thumb should be, unless a goto makes the code significantly more readable or maintainable, or you are writing some kind of low-level often-executed code where a goto might gain some efficiency, avoid it.

      --
      Momentarily, the need for the construction of new light will no longer exist.
    46. Re:Regardless of whatever code in it is faulty by sbeckstead · · Score: 1

      Yes, but I have never in the 20 years I have been writing code found a goto that I could not eliminate. I even eliminated the gotos that were in the original GCC compilers when I ported them to the AMD 29000 when I worked for a company that used them as a co-processor in the MAC II. And I re-wrote the Base 'C' libraries for that Processor based on code we purchased from somewhere. There is never a good reason to use a goto. I've written code for device drivers and I've even written a quickie OS for an embeded application and I have never used a goto in my C code.

    47. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Except for your code doesn't do the same as the original. The second condition checking in the original code doesn't run when condition1 && condition2 are true.

      That would work (but I'd rather choose goto):
      bool needs_cleanup = false;

      if (condition1 && condition2) {

      needs_cleanup = true;

      }

      if (!needs_cleanup && (issue1 || issue2)) {

      needs_cleanup = true;

      }

      if (needs_cleanup) { // clean up local vars exactly as you would have done // have done under the cleanup: label with the goto

      }

    48. Re:Regardless of whatever code in it is faulty by 1729 · · Score: 1

      Assembly is bad which is the point of using a higher level language. Assembly should be avoided as well which is why you microkernels are the most stable.

      I don't understand your point here. What does assembly language have to do with the microkernel vs. monolithic kernel debate? One could certainly write a microkernel in assembly language.

      As for assembly being something that should be avoided: it depends on the context. Higher-level languages have the advantage of easier programming and maintenance, better readability (in theory!), and portability. Assembly language allows greater control (sometimes necessary for very low-level programming), and hand-coded assembly can sometimes increase performance (though not too often these days in comparison to a good optimizing compiler).

      Today's computers have tens and sometimes hundreds of services or processes running and a single program that uses direct memory access with a pointer can cause a GP fault and bring it down. I remember the days of Windows 3.1 and having to hit the reset button.

      Again, I'm not following you here. Modern OSes have memory protection to prevent this from being an issue. You can certainly crash a program by using pointers incorrectly, but you can also generate a NullPointerException in Java. Furthermore, pointers are essential for system-level programming.

      Csharp and Java provide access to pointers indirectly through their apis so they are managed. Goto statements make spaghetti code and makes debugging hard.

      GOTO statements can lead to spaghetti code if used incorrectly. Here's an analogy: inexperienced writers are often given various rules for English composition, such as "Don't split infinitives" or "Don't end a sentence with a preposition." These are good guidelines, but they aren't absolute. Once you know why these "rules" exist, you'll find that there are times when you should ignore them. The same is true for programming with GOTOs. If you don't know why they're dangerous, then you shouldn't use them. For an experienced programmer, however, GOTOs can be very useful in some situations.

      You only found one professor who uses them.

      I know plenty of CS professors who use GOTOs, but Knuth is arguably the preeminent living computer scientist and he's also a vocal advocate of the GOTO statement.

      Pointers also cause memory leaks in programs and other errors that can be avoided by calling by value or using an api which manages the pointers indirectly.

      Since this is Slashdot, here's a car analogy: saying pointers cause memory leaks is like saying that steering wheels cause car crashes. Garbage collection is great, but it's not suited for all situations.

    49. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      That's so retarded I want to shoot you in the face.
      The entire point of the goto is to SKIP CODE THAT SHOULD NO LONGER EXECUTE.

    50. Re:Regardless of whatever code in it is faulty by Anonymous Coward · · Score: 0

      Yes, but it also means that the second if will get evaluated even if the error happens in the first one, and you cannot be sure that issue1 and issue2 are properly initialized for example. It is also slower this way (due to issue1 and issue2 being potentially evaluated).

    51. Re:Regardless of whatever code in it is faulty by againjj · · Score: 1

      Except you have broken the code, most likely: if (issue1 || issue2) { needs to become if (!needs_cleanup && (issue1 || issue2)) {. Really, good error handling is hard to get right.

      Geez, just as I was about to submit this, I noticed that it was jd142 that made the initial error, and it wasn't caught.

      Since I am editing again, I just want to say that the goto as written above really is just a finally clause, as you get in Java. These are really the types of gotos that actually have reason to exist -- or have people not written try { ... } finally { ... } in Java?

  16. Sad code, sad article by gnasher719 · · Score: 3, Interesting

    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.

    1. Re:Sad code, sad article by chalkyj · · Score: 5, Informative

      I think slashdot ate your < in the breaking line.

    2. Re:Sad code, sad article by xlv · · Score: 5, Funny

      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

      No, this is what Knuth would call an infinite loop as there's no way to terminate the loop except on the last day of each year...

    3. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      The worst part of that sort of problem is that as time goes on it takes longer and longer to execute. Not much but is gets slower by little bits each year. Blech...

      Then if you call it a lot it gets geometrically worse.

      That this sort of code exists in CE I am not surprised. The build system is one giant nightmare of batch files built ontop of visual studio 5/6. It is a very fragile system.

      Also many times the drivers and code is not even written by MS itself. It comes in from their 3rd parties with very little review or vetting.

      If you decide to use CE in your system. Heed my words bash every function and as many permutations of calls as you can and drop it right back in MS's lap. The thing really starts to fly apart when you try to actually multitask in any meaningful manner. It is a 'task pad' OS that has been bent and twisted into a 'embedded system' OS. That it breaks in weird bad ways does not surprise me. Win9x was better written...

    4. Re:Sad code, sad article by colfer · · Score: 1

      In your break line, '=' should be ''.

    5. Re:Sad code, sad article by davepermen · · Score: 1

      shouldn't it be if(day = daysInYear) or so? (or even just ) but in essence, your idea is correct and the code is much more auto-proven to be correct or wrong, as it's much simpler to understand.

    6. Re:Sad code, sad article by colfer · · Score: 1

      Ack! Yeah, it's that html thing... preview is such a speedbump...

    7. Re:Sad code, sad article by davepermen · · Score: 1

      .. html bug.. if(day <= daysInYear) or if(day < daysInYear) even.

    8. Re:Sad code, sad article by xlv · · Score: 1

      or at least it would be if it was "==" instead of "=" so next time I should double check before pointing problems in somebody else's code...

      In any case, as others have posted, the loop termination is not correctly implemented but pointing out the weird termination because of a missing '<' is not as funny.

    9. Re:Sad code, sad article by Anonymous Coward · · Score: 1, Insightful

      Actually, that's what Knuth wouldn't call a loop, since it only runs once. That's a single = not a == in the if there, so it would only terminate if daysInYear is 0, and that gets set to 366 or 365.

    10. Re:Sad code, sad article by gnasher719 · · Score: 4, Informative

      It's a bug in the Slashdot software, eating "less than" and "greater than" characters in "Plain Old Text" mode.

    11. Re:Sad code, sad article by Jack9 · · Score: 1

      The comedy of corrective replies are discovering the original intent.

      --

      Often wrong but never in doubt.
      I am Jack9.
      Everyone knows me.
    12. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      Thankfully CE6 fixes almost all these complaints and is very much a "real" OS.

    13. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      Nah, it loops fine.

      It just leaves a little early because of the single equal sign. ;-)

    14. Re:Sad code, sad article by corrie · · Score: 1


      if (day>365) {
        for (;;) {
            int daysInYear = IsLeapYear (year) ? 366 : 365;
            if (day = daysInYear) break;
            day -= daysInYear; year += 1;
        }
      }

    15. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      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

      No, this is what Knuth would call an infinite loop as there's no way to terminate the loop except on the last day of each year...

      wrong. The expression "if (day = daysInYear)" is always true (this is C, not pascal), causing the end of the loop before completing the first iteration.

    16. Re:Sad code, sad article by rfreedman · · Score: 1

      I assume that you meant:

      if(day == daysInYear) break;

    17. Re:Sad code, sad article by reg · · Score: 1

      I always wonder why C (and C like languages) don't have a loop like this:

      do {
      block1();
      } while (condition) {
      block2();
      }

      It seems easy to parse and would be quite useful since this kind of loop is all over the place... IMHO it's more readable than a while(1) loop with a break.

      Regards,
      -Jeremy

    18. Re:Sad code, sad article by Phroggy · · Score: 1

      It's a bug in the Slashdot software, eating "less than" and "greater than" characters in "Plain Old Text" mode.

      If "Plain Old Text" mode had a more intuitive name, that would help. What most people think of as "plain old text" is what Slashdot calls "Extrans", which isn't a label most people would recognize. What Slashdot calls "Plain Old Text" is an attempt to "do the right thing" when you use a combination of HTML and plain text, with the assumption that your plain text doesn't contain greater-than/less-than/ampersand characters.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    19. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      Wrong again.
      Note that it is a single = (not a double ==).
      Which means that the condition of the if command
      will always be true and the loop will exit immediately.

      Happy new year.

    20. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      Even if the wasn't eaten, it is still not an infinite loop. The "if (day = daysInYear)" will always break since daysInYear is either 365 or 366.

    21. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      This article's pretty much dead by now, but I think this would save a few cycles: //Knock out the even chunks of four years at 365 days/year plus one
      while (days > 1461)
      {
            days -= 1461;
            years +=4
      } //Now we know the next year is a leap year (we started in 1980, right?) and after it will come only normal years (less than four years left in the amount if it made it this far)
      if (days > 366)
      {
            days -= 366;
            years++; //...and all the rest are normal years.
            while (days > 365)
            {
                  days -= 365
                  years++
            }
      }
      Excuse the formatting errors that I'm sure will get through regardless of how many times I hit the preview button (thanks /.). This is longer than your version, but a bit more readable I think, and all in all it uses (in the best case) 75% less ifs and not a single call to IsLeapYear (which is largely unnecessary imo, mod 4 anyone?)
      Hopefully someone will read this and point out the glaring error I must have missed.

    22. Re:Sad code, sad article by Anonymous Coward · · Score: 0

      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

      No, this is what Knuth would call an infinite loop as there's no way to terminate the loop except on the last day of each year...

      Hmmm no, ... Actually, it would break out any time "days" was assigned a non zero value... since the if statement evaluates the variable after the assignment (in C/C++). Notice it is a = not ==. ;)

      But, yeah, it was prob just a formatting bug.

  17. Modified Julian Day by janwedekind · · Score: 1

    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

    1. Re:Modified Julian Day by rcw-home · · Score: 4, Funny

      I highly recommend that in cases like this, programmers be good Catholics and abide by the decree of Pope Gregory XIII. Software written to work with modern dates should use Gregorian, not Julian. Or did you mean ordinal?

      From the article you linked to: The use of Julian date to refer to the day-of-year (ordinal date) is usually considered to be incorrect, however it is widely used that way in the earth sciences and computer programming.

    2. Re:Modified Julian Day by plopez · · Score: 1

      Most people mean DOY when they say Julian.

      --
      putting the 'B' in LGBTQ+
    3. Re:Modified Julian Day by rcw-home · · Score: 1

      And maybe after society rebuilds itself from global catastrophe, and all memory of the Roman Empire or the frickin' month of July have been long forgotten, they'll be right.

    4. Re:Modified Julian Day by Anonymous Coward · · Score: 0

      The word "Julian" comes up in at least three contexts in discussion of calendars and dates. You, and one of your respondents are talking about usages #2 and #3, respectively. OP refers to usage #1 (a linear mapping of dates from c. 4700 BC onward).

    5. Re:Modified Julian Day by rcw-home · · Score: 2, Interesting

      OP refers to usage #1 (a linear mapping of dates from c. 4700 BC onward).

      You'd seriously use this for doing calculations between two dates on a modern calendar? You'd convert beginning-of-the-day-midnight to middle-of-the-day-midnight and back again? You'd flip a coin and decide whether or not to store dates internally in a common timezone? You'd add in your own leap years when necessary? (which brings us back to this bug - please look at what exactly the faulty source code was trying to do!)

      There are very good reasons for internally storing dates as ordinal. But unless there is a good reason not to, please use your operating system's (or SQL database's, etc) native format/epoch for it, and please use their code, not your own, for calculating those dates. And if you do find yourself in a position where you're the one writing that code for others' benefit, please be at least as pedantic as I have been in this thread. Society at large is counting on you.

    6. Re:Modified Julian Day by gzipped_tar · · Score: 1

      I happen to have done some programming in this area. Just FYI, most of the astronomy code uses the Proleptic Gregorian Calendar which does *not* handle the transition from Julian calendar to Gregorian in 1582, by design. (BTW the "Julian" in Julian Calendar has nothing to do with the Julian Date.) This saves the effort of dealing with the mess of the "real" Julian Calendar which was plainly wrong about certain stuff (e.g. leap year).

      Also, many astronomers' idea about "calendar" is very different from the general public and there can be subtle traps when trying to use astronomic code for a civilian application.

      Examples:
      1. The year 0, which is not valid in Gregorian, is seen very frequently seen in astronomical calculations. It means the year before AD 1 in Proleptic Gregorian. To further confuse the matter, that year was before the 1582 reform...
      2. The idea of dates like "January 31.75" and "July 0" or even "July -1". They are valid astronomy-speak and frequently seen in ephemeris calculations. They usually prove to be useful for internal numeric computation. But be sure the code handling date representation on a higher level doesn't get confused. And think of "February 28.75"...
      3. Leap seconds. You may think the Julian Day is a continuous, but Julian Day may refer to different things. It's no more that a notation which can be used for different time measurements. Julian Day for TAI is continuous but Julian Day for UTC is not. Fortunately, due to the nature of UTC it is only used at representation level and almost never in internal calculation.
      4. Some of the good algorithms like the Fliegel-van Flandern for Julian Day calculation are very robust and "works right out of the box". However, it can be very cumbersome to implement in a language in which the rules for integer division is not truncation. For instance the default behavior in Python 2.x doesn't work, where (1 / 4) == 0 and (-1 / 4) == -1.

      </rants>

      --
      Colorless green Cthulhu waits dreaming furiously.
    7. Re:Modified Julian Day by janwedekind · · Score: 1

      Thanks for elaborating. Maybe I should have been more accurate. One does not need to know all this for doing date conversions. However one may need to know this when dealing with astronomy software.
      * Astronomy software uses ephemeridal time (ET) for computing the position of the planets and comets. ET is a linear time-measure.
      * Astronomy software uses universal time (UT) to compute the rotation of the earth. ET-UT is at approx 60 seconds and it increases every year because the rotation of the earth is slowing down due to tidal forces. The difference ET-UT is quite significant when one wants to predict where a solar eclipse is going to occur.
      * Ordinary computer software just uses UTC. UTC runs at the same "speed" as ET and the difference UTC-UT is kept below 0.9 seconds by introducing leap seconds.

  18. No problem since 1966 in FORTRAN by slugmass · · Score: 2, Informative

    integer function f_isleap(year)
                IMPLICIT NONE
    c
    c Purpose :: Return 0 if a year is NOT leap year and a 1 otherwise.
    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) .or.
              % ((MOD(Year,4).eq.0) .and.
                        (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.

    1. Re:No problem since 1966 in FORTRAN by Anonymous Coward · · Score: 1, Funny

      Lovely. The coder who admonishes other for not using FORTRAN presents a solution for the wrong problem. How do you shoot yourself in the foot with FORTRAN?

    2. Re:No problem since 1966 in FORTRAN by Guy+Harris · · Score: 1

      The problem wasn't with the code that determined whether a year is a leap year or not (which was correct, and was using the same algorithm as your FORTRAN example). The problem was with the loop, and somebody could've made the same error in FORTRAN 66.

    3. Re:No problem since 1966 in FORTRAN by Anonymous Coward · · Score: 0

      FORTRAN is not fancy enough for super cool C# coders.

      AFAIK "super cool C# coders" do not exist, at least not in the context of developing C#. There are, however, plenty of super cool C coders who would have avoided making the mistake made by the Freescale driver developer(s).

  19. Re:Old by larry+bagina · · Score: 5, Insightful

    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.

  20. MOD PARENT UP Re:Why write any date/time code? by exphose · · Score: 5, Insightful

    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.

    1. Re:MOD PARENT UP Re:Why write any date/time code? by p0tat03 · · Score: 1

      And an example of where closed-source binary drivers can go horribly wrong :) But really, no one can be expected to QA every single line of code that's shipped through their device (honestly, a date function fuckup?)... what this really says is the importance of proper QA at the driver-developer level.

    2. Re:MOD PARENT UP Re:Why write any date/time code? by Anonymous Coward · · Score: 0

      This happened to be an open source driver though.

    3. Re:MOD PARENT UP Re:Why write any date/time code? by JoeMerchant · · Score: 3, Insightful

      But really, no one can be expected to QA every single line of code that's shipped through their device

      All depends on the level of concern - for a music player, what the hell, it's only the company's reputation that's riding on it... (now, if the company isn't already a laughingstock, maybe this might matter.) If this were code on a Mars Surveyor mission whose failure would set back an entire program by 2 years or more - I'd be checking every line of code, everywhere, three times.

    4. Re:MOD PARENT UP Re:Why write any date/time code? by p0tat03 · · Score: 1

      Right, which is why the exact cause of the problem was discovered within hours of the first reports. Imagine if MS was swarmed with angry Zune customers, and had to talk to Freescale to see if they could look in their code and solve it... For a lesser bug or lesser customer (smaller than MS) this could have taken ages. This way MS can also ship a fix out immediately by patching it themselves, instead of waiting for Freescale to roll out a new binary.

    5. Re:MOD PARENT UP Re:Why write any date/time code? by Anonymous Coward · · Score: 0

      Give me a fucking break. To do this on most embedded systems would be the equivalent of checking the entire source code of Windows XP every time you wrote an application.

    6. Re:MOD PARENT UP Re:Why write any date/time code? by moosesocks · · Score: 1

      Honestly, of all the places I'd expect a hardware manufacturer to screw up the drivers, the Real Time Clock would be just about the last thing on my list.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
  21. Probably Not A Widespread Issue by nato10 · · Score: 5, Informative

    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.

    1. Re:Probably Not A Widespread Issue by TheSunborn · · Score: 3, Funny

      I still wonder: Why is code that translate from a number of days, to a year hardware dependent?

      Getting the number of seconds since epos is hardware depending, but translating this to other time measurements should not be,
      unless they are building a time machine.

    2. Re:Probably Not A Widespread Issue by radtea · · Score: 1

      As such, the implementation is hardware-dependent, which is why there isn't a standard implementation of this function for Windows CE.

      It is nevertheless the case, as others here have pointed out, that the correct way of handling date problems is to use Julian dates and day numbers, for which all these algorithms exist in well-documented forms. Getting the Julian Day number in this case should be trivial, as the function gets the number of days since January 1st 1980 as an argument, so it is just a matter of adding that to the Julian Day of the start date.

      If you can't use a third-party calender/time lib (which is obviously the preferred solution given the hellish complexity and enormous subtlety of correct date/time representation) year/month/day divisions should be kept STRICTLY in the UI, and all internal date representations and calculations should be in terms of Julian Day or Date.

      --
      Blasphemy is a human right. Blasphemophobia kills.
    3. Re:Probably Not A Widespread Issue by petermgreen · · Score: 2, Interesting

      Different RTC chips measure time in different ways. This particular one used time of day and a day count afaict. Some however give you a time broken down into hours,minuites,seconds,days,months and years.

      So if the API was designed arround the latter style of RTC chip the hardware vendor would have to write code to convert to the format the API expects and when writing driver code you generally can't just go and call your regular libraries.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    4. Re:Probably Not A Widespread Issue by Anonymous Coward · · Score: 0

      I think it should all be represented by Star Date and only converted to legacy dates in the UI. Star Dates can be represented easily as a double, but for a low power processor like this you may want to keep it as two int's - one for the "days" part of the Star Date and one for the "hours" part.

    5. Re:Probably Not A Widespread Issue by tlhIngan · · Score: 1

      As such, the implementation is hardware-dependent, which is why there isn't a standard implementation of this function for Windows CE.

      It is nevertheless the case, as others here have pointed out, that the correct way of handling date problems is to use Julian dates and day numbers, for which all these algorithms exist in well-documented forms. Getting the Julian Day number in this case should be trivial, as the function gets the number of days since January 1st 1980 as an argument, so it is just a matter of adding that to the Julian Day of the start date.

      If you can't use a third-party calender/time lib (which is obviously the preferred solution given the hellish complexity and enormous subtlety of correct date/time representation) year/month/day divisions should be kept STRICTLY in the UI, and all internal date representations and calculations should be in terms of Julian Day or Date.

      And the thing is, the functions exist in Windows CE. In Windows CE, the functions exist as SystemTimeToFileTime, and FileTimeToSystemTime (or similar - it's a standard date function), which convert between nice year/month/day/hour/minute/section to a 64-bit monotonically increasing number, a "file time" (number of 100-nanosecond intervals since Jan 1, 1904, I believe). In the kernel, they exist as their "K" counterparts. Microsoft wasn't this helpful because they feel date functions are useful, they put it in so people won't screw up their date computations.

      An RTC driver is trivial. GetSystemTime() gets you a SYSTEMTIME. SystemTimeToFileTime(), gets you a FILETIME. Do another SystemTimeToFileTime on your chosen epoch. Subtract the first from the second, and you have the number of 100-nanosecond periods from your epoch to "now". Multiply by 10,000,000 to get it in seconds. Divide that figure by 86400 (24*60*60) to get days. Take the remainder to get seconds since midnight. And for those arguing about 86400 - the hardware RTC chip is probably automatically rolling over every 86400 seconds.

      And now, the driver only relies on simple well-defined multiplication and division of known quantities of time. The OS is doing the heavy lifting of date calculations in those function calls - handling leap years and other stuff. Sure the OS library may have a bug in it, but at least the bug is consistently in all applications using those functions, and I'd like to bet that the API call is probably more well tested than the date code you'd write.

  22. Talked-about layoffs at MSFT by postmortem · · Score: 0, Troll

    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.

    1. Re:Talked-about layoffs at MSFT by Culture20 · · Score: 1

      Nothing makes programmers better than increased workload, stress, and loss of the coworkers that didn't properly comment their code.
      /sarcasm

    2. Re:Talked-about layoffs at MSFT by Jaime2 · · Score: 2, Interesting

      Microsoft is famous for "stack-ranking" employees at review time. This means that somebody in every group will get a "worst of the group" review and somebody will get "best of the group". If you are in the bottom 10% at MSFT, you are never going to get a raise and you will eventually quit.

  23. exact by binaryseraph · · Score: 0, Flamebait

    I think the exact cause can be summed up as this: It's Microsoft.

    1. Re:exact by binaryseraph · · Score: 0

      ouch- marked as flamebait by a microsoft sympathizer. ZING!

  24. When did the bug happen? by jrumney · · Score: 1

    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?

    1. Re:When did the bug happen? by cbhacking · · Score: 1

      It started on the 31st, as you surmised. If you didn't turn the device on between midnight on the 31st and midnight on the 1st (according to UTC, adjust for time zone as needed) you didn't see the issue at all.

      --
      There's no place I could be, since I've found Serenity...
    2. Re:When did the bug happen? by tabrisnet · · Score: 1

      think timezones vs UTC.

    3. Re:When did the bug happen? by jrumney · · Score: 1

      Right, but these reports are coming out of the US mostly, so shouldn't they be saying the problem started on the 30 December? Or are there further bugs in the timezone handling of the Zune that make timezones work backwards?

    4. Re:When did the bug happen? by tabrisnet · · Score: 1

      It wouldn't occur until midnight UTC, or if localtime is used on their clocks, midnight local time. Either way, it wouldn't occur before the evening of the 31st, and may not be noticed until after the new years eve party.

  25. Free Book web site. by Futurepower(R) · · Score: 3, Informative

    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

    1. Re:Free Book web site. by Creepy+Crawler · · Score: 0

      err. Try downloading the archive, unraring it, and reading the PDF inside.

      Hint: It matches the book displayed on Amazon.

      --
    2. Re:Free Book web site. by Anonymous Coward · · Score: 0

      free-ebooksnet.com is a scam.

      Is infested with ads.

      fdx

    3. Re:Free Book web site. by Creepy+Crawler · · Score: 1

      But the rapidshare link and the resulting 45$ book for free makes it "legit".

      muhahaha

      --
  26. Not from what I saw. by Anonymous Coward · · Score: 0

    Really? I didn't see many examples of alternate solutions to this.

  27. Microsoft is just misunderstood, that's all. by Anonymous Coward · · Score: 0

    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.

  28. Obligatory XKCD by Failed+Physicist · · Score: 3, Funny
  29. Not so uncommon by fermion · · Score: 2, Interesting
    These functions that are only used once in great while are the devil to test. I think anyone who has programmed in any complex situation will have to admit to one of these silly bugs, and maybe even the bug going to production.

    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.

    int daysperyear;
    for(;;)
    {
    daysperyear=howmaydaysthisyear(year);
    if(days>daysperyear)
    {
    days -= daysperyear;
    year++;
    }
    else
    {
    break;
    }
    };

    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
  30. We don't have time for QA by plopez · · Score: 1

    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+
    1. Re:We don't have time for QA by AnalPerfume · · Score: 1

      This can be the mindset when you're working to the clock, watching for 5pm to tick past, doing make work to look busy. You have no love for the project, if there are bugs, so what? Just as long as the consequences (if any) can be aimed at someone else. The bottom line is that you continue to get your pay cheque, not the quality of the project.

      OSS by comparison is largely done by volunteers with a love for the project, who actually take pride in their work and the work of others. If you're giving your own free time to do something you're not clock watching doing make work.

  31. The whole industrial is bad by kentsin · · Score: 0

    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.

  32. The real problem by rudy_wayne · · Score: 1

    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!

    1. Re:The real problem by Coopjust · · Score: 1

      I think it DOES relate to playing the media. You have to renew your licenses regularly for music that you get on a "rent for $X a month" to make sure you're actually still subscribed. Those licenses are issued to last from date A to date B - it has to check that any DRMed media is within the time period for a valid license.

    2. Re:The real problem by causality · · Score: 1

      I think it DOES relate to playing the media. You have to renew your licenses regularly for music that you get on a "rent for $X a month" to make sure you're actually still subscribed. Those licenses are issued to last from date A to date B - it has to check that any DRMed media is within the time period for a valid license.

      Wouldn't that be interesting if the enforcement of DRM is the only reason why a device dedicated to playing media would ever need to worry about things like dates and leap years? "Sorry folks, this show-stopper happened only because we wanted to implement a feature that none of you have asked for and that many of you are vehemently against. We put customers first. Really, we do!"

      I can understand some basic time functions to track minutes/seconds/etc as media is being played, but does anyone know of any reason other than DRM why a media player would need this kind of calendar function? If there are none, then I can't say I'm sad to see a good iteration of the "needless complexity" argument against DRM. Those who are thinkers see such a possibility as an eventuality and incorporate it into their views of the subject, whatever those may be. However, the vast majority of the population needs concrete examples like this before they recognize the potential disadvantages of buying, and thus using their dollars to reward, systems and features that are not in their own interests.

      --
      It is a miracle that curiosity survives formal education. - Einstein
    3. Re:The real problem by /dev/trash · · Score: 1

      How else can the owners of the music you rented, know to lock the files so you have to pay extra to watch what you paid for earlier?

    4. Re:The real problem by psetzer · · Score: 1

      The RTC is used for a variety of purposes even if it doesn't need the current year. Anything where the player waits even for a few seconds uses that clock or the interrupt timer. Linux uses the interrupt timer by default in those cases, but it initializes the timer and synchronizes it against the RTC if it exists to protect against drift and to account for leap seconds and the like.

      --
      "Anyone who attempts to generate random numbers by deterministic means is living in a state of sin." -- John von Neumann
  33. This has happened before... by Anonymous Coward · · Score: 0

    ... 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

  34. Does not explain one important thing... by jkrise · · Score: 1

    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....
    1. Re:Does not explain one important thing... by Anonymous Coward · · Score: 0

      Yes, every time code changes there's no possibility of introducing new errors on accident, it had to be intentional!

      Get over yourself, you FUD-spewing retard.

    2. Re:Does not explain one important thing... by Idimmu+Xul · · Score: 1

      Looks like the bug was deliberately introduced as a firmware update. That has to be properly explained.

      Wow, that's quite a leap you've made there. Hate Microsoft and conspiracy theorise much? Hey, have you seen that film Zeitgeist? Also it's nice to finally meet someone who shares the same thoughts on Building 7!

      --
      The problem with slashdot is that most of its users were bullied and stuffed into lockers as kids!
  35. Calendrical Calculations by kabloom · · Score: 4, Interesting

    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.

    1. Re:Calendrical Calculations by larry+bagina · · Score: 2, Insightful

      division (and modulo) are much slower than integer Math on the ARM.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    2. Re:Calendrical Calculations by kumanopuusan · · Score: 1

      Is division actually slower than looping?

      --
      Use of the words "good", "bad" or "evil" is almost invariably the result of oversimplification.
    3. Re:Calendrical Calculations by should_be_linear · · Score: 1

      this should work until year 2100, no loops:

      void getYearAndDaysOffsSince1980(int n, int& year, int& days) {
         if ( (n < 0) || (n > (120*365)) ) {
            HANDLE ERROR;
         }
         year = n / 365;
         day = n % 365 + 1;
         add_days = (year + 3) / 4;
         day -= add_days;
         if (day <= 0) {
           day += (--year % 4) ? 365 : 366;
         }
         year += 1980;
      }

      --
      839*929
    4. Re:Calendrical Calculations by pavon · · Score: 1

      Normally that would be true, but not in this case.

      Unless the ARM instruction set has changed since I last used it, there is no DIV instruction, and the general case way of implementing it is to subtract in a loop. Therefore, with a dumb compiler, the way the code is currently implemented would be faster than using divisions and modulus, because it combines the multiple loops into a single one.

      However, there are many ways to optimize this for special cases, and one of the biggest special cases is division by a constant. In that case you can convert the divide to a shift and multiply, which will be faster than a loop in the vast majority of cases.

  36. I loved the PR from Microsoft by Nicolas+MONNET · · Score: 1

    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.

    1. Re:I loved the PR from Microsoft by Ant+P. · · Score: 1

      They're probably surprised the other planned obsolescence features had failed to activate.

  37. Blame it on the RIAA (or, because of copyrights?) by Anonymous Coward · · Score: 0

    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.

  38. WWSD? by qazwart · · Score: 2, Interesting

    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.

    1. Re:WWSD? by bigbigbison · · Score: 1

      Well, unlike the zune the ipod actually has a user accessable calendar and clock in it so it actually has a good reason to keep track of the date.

      In all likelihood, the zune keeps track of the date so that it can tell if you have authenticated your drmed music within the allowed number of days or something like that

      --
      http://www.popularculturegaming.com -- my blog about the culture of videogame players
    2. Re:WWSD? by Slashdot+Parent · · Score: 1

      These days, it's normally more like, "If you have a common programming task that everyone and his mother has to solve, chances are there is a library/STL/JDK/whatever routine available that has had all the bugs worked out of it years ago. You'd be an idiot to write your own."

      A huge pet peeve of mine is reviewing code where someone has reimplemented some type of date, math, sort, data structure, or similar construct. Chances are greater than 90% that there is a totally unnecessary bug in there somewhere; and chances are greater than 99.9% that the library function is in O(way the fuck less than the homebrew function).

      --
      They don't grade fathers, but if your daughter's a stripper, you fucked up. --Chris Rock
  39. Four is a power of two. Use that fact!!! by Anonymous Coward · · Score: 0

    static int IsLeapYear( int year )
    {

    // stop doing so many damn divisions!
            if ( year & 0x011 ) return 0;

            switch ( year % 400 )
            {
            case 0:
                    break;
            case 100:
            case 200:
            case 300:
                    return 0;
                    break;
            default:
                    break;
            }

            return( 1 );
    }

  40. Was it a bug? by santix · · Score: 1

    Or an undocumented feature?

  41. Re:Old by Goldberg's+Pants · · Score: 4, Funny

    First to finish is not always a good thing. Just ask your girlfriend.

  42. <scm> blame by CC12123 · · Score: 1

    Hats off to the coder who blamed on that one. You've made history!

  43. Thats crazy thinking! by msgmonkey · · Score: 1

    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.

    1. Re:Thats crazy thinking! by hab136 · · Score: 1

      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.

      The point your teacher was probably trying to make is that not all instructions cost the same CPU time, even if they use the same number of instructions to issue. Depending on when your teacher learned computers, what architecture the class had in mind, and how old his textbook was, his statement might have been true for the cases he was thinking of.

      Some early processors (such as original PDP-11) did not have a DIV instruction at first, so Pascal (and other languages) would have had to emulate it. Some embedded processors also do not have a divide instruction. Dividing isn't universal in processor instruction sets. The simplest (although not usually the most efficient) way to emulate a divide is with repeated subtraction. It's also possible for processors that support a divide instruction to internally subtract in a loop. Pascal (and other languages) also had floating point libraries that couldn't rely on the floating point unit being there; it's entirely possible that early versions of those libraries used repeated subtraction.

      Anyways, the question that should've come to your mind after that is "how much slower is it?" and then run a timing test of divisions vs subtractions. For example time 1,000,000 loops of (3000-3), and then time 1,000 loops of (3,000/3). If they come out the same, then your division might be using repeated subtraction. Use 3 to avoid the edge cases of anything divided by one is itself, and anything divided by 2 can be bit-shifted.

      There are better ways to test, but since Pascal is normally a beginning teaching language this would be a nice simple one that beginning students should think of and be able to do. If the division came out faster, you would have a reason to believe that it wasn't done through repeated subtraction on that CPU and version of Pascal (and libraries). You could then investigate how it was done (there's some fancy tricks depending on the CPU).

      This reminds me of a time when a student who was taking Pascal didn't know his computer architecture, sad but true. :)

    2. Re:Thats crazy thinking! by 7+digits · · Score: 2, Informative

      How exactly do you think that divisions are implemented ? Even in silicon ? Did you realize that the number of cycle for a DIV instruction is high and dependent on the operand size ?

      Ever wondered why the x86 DIV was 14 cycles for 8bits operands, 22 cycles for 16bits and 38 cycles for 32bits ? (hint 6 cycles constant data access + 1 cycle per bit in the subtract/shift loop)

      And if the time your teacher told you that was a few years ago, before processor had hardware divide instruction that implemented the loop in silicon, then the pascal run time had to implement division by a series of subtractions and halving...

      Now, if he told you that it just subtracted (without halving) then, yeah, he was wrong...

    3. Re:Thats crazy thinking! by msgmonkey · · Score: 1

      How exactly do you think that divisions are implemented ? Even in silicon ? Did you realize that the number of cycle for a DIV instruction is high and dependent on the operand size ?

      Ever wondered why the x86 DIV was 14 cycles for 8bits operands, 22 cycles for 16bits and 38 cycles for 32bits ? (hint 6 cycles constant data access + 1 cycle per bit in the subtract/shift loop)

      And if the time your teacher told you that was a few years ago, before processor had hardware divide instruction that implemented the loop in silicon, then the pascal run time had to implement division by a series of subtractions and halving...

      Now, if he told you that it just subtracted (without halving) then, yeah, he was wrong...

      No it was the latter case, ie a loop that kept on subtracting the divisor until 0 or < divisor. The same kind of code talked about here, thats why it came to mind.

      Btw, modern x86 processors take less then 1 cycle per bit to division but obviously the algo is the same.

    4. Re:Thats crazy thinking! by msgmonkey · · Score: 1

      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.

      The point your teacher was probably trying to make is that not all instructions cost the same CPU time, even if they use the same number of instructions to issue. Depending on when your teacher learned computers, what architecture the class had in mind, and how old his textbook was, his statement might have been true for the cases he was thinking of.

      Some early processors (such as original PDP-11) did not have a DIV instruction at first, so Pascal (and other languages) would have had to emulate it. Some embedded processors also do not have a divide instruction. Dividing isn't universal in processor instruction sets. The simplest (although not usually the most efficient) way to emulate a divide is with repeated subtraction. It's also possible for processors that support a divide instruction to internally subtract in a loop. Pascal (and other languages) also had floating point libraries that couldn't rely on the floating point unit being there; it's entirely possible that early versions of those libraries used repeated subtraction.

      Anyways, the question that should've come to your mind after that is "how much slower is it?" and then run a timing test of divisions vs subtractions. For example time 1,000,000 loops of (3000-3), and then time 1,000 loops of (3,000/3). If they come out the same, then your division might be using repeated subtraction. Use 3 to avoid the edge cases of anything divided by one is itself, and anything divided by 2 can be bit-shifted.

      There are better ways to test, but since Pascal is normally a beginning teaching language this would be a nice simple one that beginning students should think of and be able to do. If the division came out faster, you would have a reason to believe that it wasn't done through repeated subtraction on that CPU and version of Pascal (and libraries). You could then investigate how it was done (there's some fancy tricks depending on the CPU).

      This reminds me of a time when a student who was taking Pascal didn't know his computer architecture, sad but true. :)

      You give the teacher a lot more credit then they deserve but I can understand if you was trying to make a point about performance divide would be a good example however I seem to recall that this they were n't actually a CS teacher but had "got into" programing at a later date and the class was an introduction to programing.

      It was just a passing comment they made that stuck in my mind because the first thing I thougt was how slow that would be where the dividend was large and the divisor small.

    5. Re:Thats crazy thinking! by 7+digits · · Score: 1

      Oh, in that case I hope he prevented you do divide negative numbers...

      Btw, I think there are some additional astute stuff in modern x86 processor, and the use of tables. I'm not 100% sure, though.

  44. why not use a standard C library function instead? by paleshadows · · Score: 1

    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...

  45. Not only a zune bug toshiba gigabeat affected too by bigbigbison · · Score: 3, Informative
    --
    http://www.popularculturegaming.com -- my blog about the culture of videogame players
  46. Or by msgmonkey · · Score: 1

    Or used hardware from another manufacturer.

    1. Re:Or by p0tat03 · · Score: 1

      This seems more likely. AFAIK Freescale's the guys who do low-power x86 chips, which is an idea that never really panned out. Most devices still use ARM chips, and MS probably joined the club with the 2nd and 3rd generations.

    2. Re:Or by Why2K · · Score: 1

      The Freescale chip in question is an ARM -- the i.MX31 (this driver is actually for the power management companion IC). Freescale does not and never has made low power x86 chips. In fact, being the spin-off of Motorola's semiconductor division and the home of the 68K processor line, they would probably find that suggestion offensive!

  47. Not QA's fault by Sleepy · · Score: 3, Insightful

    "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.

    1. Re:Not QA's fault by RyuuzakiTetsuya · · Score: 1

      Neither microsoft nor Toshiba are startups by any measure. this is one hell of an embarrassment.

      --
      Non impediti ratione cogitationus.
    2. Re:Not QA's fault by the_wesman · · Score: 1

      yeah - this is not QA's fault - this chunk of code should have been united tested - if it was unit tested, the tests were not sufficient

      no QA group is going to be tasked with "run the tests on monday, then run them on tuesday just to make sure that there's nothing monday-specific in the code"

      --
      calling all destroyers
    3. Re:Not QA's fault by Sleepy · · Score: 1

      Neither microsoft nor Toshiba are startups by any measure.

      Agreed - but what's your point?

      Your comment has nothing to do with my debunking of the "QA is screwing off instead of testing" mentality evident in the original story and several comments.

      I don't see where the Microsoft and Toshiba 'startups' comment comes from either. Microsoft and Toshiba are irrelevant here -- this is a bug in a BINARY closed-source third party driver.

      Trust me I'm NO FAN of Microsoft (read my 10+ years of posts here) - this is a supplier problem. Ultimately it becomes Microsoft's problem, and you can bet for now on they'll demand more completed-tests documentation from their suppliers. Which is a good thing, as it will force the cowboy programmers at startups to sacrifice a bit more of their time on documentation, instead of racing ahead with undocumented processes.

      If anything, this fiasco shines a big light on just how dangerous it is to bet your product on Windows, or more specifically, closed-source stacks.

  48. Here's what TDD would have really done by SuperKendall · · Score: 2, Interesting

    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
    1. Re:Here's what TDD would have really done by Gorimek · · Score: 2, Interesting

      There is some confusion here

      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.

      That is not Test Driven Development.

      In TDD, you actually let the tests drive the development. You first write a test, then the simplest code that will satisfy it. Then add more tests/assertions and modify the code. Rinse and repeat until you've run out of edge cases. For a function like this, you'd probably do 3-5 iterations. Sounds like a lot, but it shouldn't take more than 10-20 minutes.

      Of course there can still be bugs, but it's much less likely when every line you write is in direct response to, and is executed and verified by, a test. Actually executing the code, rather than looking at it and thinking "yeah, that looks right" gives much better results. I've done both models for years and would never go back.

      Writing tests after the code is a fine practice too. It's much better (and easier) than writing no tests, but TDD is a quantum leap beyond that. It is an acquired skill though. If you're not learning it from someone who knows the techniques, it's hard to get very effective with it.

    2. Re:Here's what TDD would have really done by Anonymous Coward · · Score: 0

      >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.

      uh, I think you got the first two steps the wrong way round there buddy.

      >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.

      well then perhaps you should learn to think better

      >Unfortunately it has the same ossifying effect >where refactoring is harder as you go along >because tests must be altered along with code.

      Actually it makes refactoring easier because you have a suite of tests to let you know when you screw up. If you find that the tests are making it harder then *you are doing it wrong*

      I'm so sick of people who insist that a technique is flawed because they never took the time to learn how to do it properly

    3. Re:Here's what TDD would have really done by Chirs · · Score: 1

      There are some cases where TDD doesn't work very well...hardware fault detection/handling, for instance.

      In this particular case, it probably would have made sense to compare the output of the written code to the glibc output for a large set of inputs (say a few hundred years worth or so, on a large computer that comparison shouldn't take very long).

    4. Re:Here's what TDD would have really done by SuperKendall · · Score: 1

      Ah, but if you read the rest of my post you'll see that in fact I assume the test was written first - I just got the order of the list slightly wrong. The problem is that in fact I've found you think of more edge cases when writing code to handle a real problem than just writing (again as I said) a raw list of possible inputs to a method. I propose that few people would think to add the last day of a leap year in a test initially.

      --
      "There is more worth loving than we have strength to love." - Brian Jay Stanley
    5. Re:Here's what TDD would have really done by SuperKendall · · Score: 1

      Now that is an excellent idea, fuzz testing is I think a more powerful way to find real issues with code.

      I saw another tool once long ago that would take in a schema and produce valid, though random, data you could point an application at. As you might imagine it took a little work to ACTUALLY define all the rules the data needed to follow (not all rules can be expressed in a schema) but when that was firing on all cylinders it was truly excellent at finding problems no test could ever hope to find (I know because we also had a test suite).

      --
      "There is more worth loving than we have strength to love." - Brian Jay Stanley
    6. Re:Here's what TDD would have really done by Imagix · · Score: 1

      3) Microsoft spends one hour fixing bug (assuming documentation and source control and test of fix)

      You forgot steps 4+ which involve days of work with marketing and other departments in order to communicate with customers and the actual deployment of the fix. Plus other intangibles

      Now lets look at that timeline with TDD:

      1) Microsoft writes method (let's say one hour again)

      Bzzt. Wrong. You write the test first.

      2) Microsoft writes test for method. Test includes random dates but not December 31st, 2008. One hour.

      Another problem. You write the test to cover all of the edge cases. There are no real random dates in there. The rest of your points just don't happen. Unless you fouled up writing your tests in the first place. So let's assume 2 hours.

      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.

      You're supposed to write the tests first. However this allows you to write code without the concern of not missing critical functionality. If it were critical, there would be a test for it.

      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.

      Known as coding by the seat of your pants. One point of TDD is that one considers what the code is supposed to be doing first, then expressing it. Not trying to figure it out as you go.

      Another potential issue is that tests tend to be written by the programmer who produced the original code,

      Ahem. TDD is that you're supposed to have the tests before the code, not after. And if you're attempting to apply this to code which isn't built with TDD, then you may write some tests to cover the current behaviour (not necessarily the code), and then write new tests to exercise whatever new functionality and/or but that has been discovered.

      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.

      Yep... QA is good. And hopefully populated with people who have a knack for and/or enjoy writing test code. We've got a guy who if he looks at the computer wrong your program explodes. And much like our QA processes, the guy who claims a bug is fixed cannot be the person to verify it's fixed. Same here, the guy writing the functionality shouldn't be the guy writing the tests.

    7. Re:Here's what TDD would have really done by Anonymous Coward · · Score: 0

      What you describe is simply bad TDD.

      You wouldn't accidentally "miss" Dec 31 2008. A proper test would try *all* dates, from the 1800's through well into 2500 or beyond. Test it against the library of your development workstation (if your code is not the same library). Test it against the algorithm given in wikipedia. Test it agaist its inverse (days -> Y M D -> days; and Y M D -> days -> Y M D). Test it against known patterns, for example the day-of-the-week should cycle when incrementing through days.

      Computers are fast, there's no reason to skimp on the tests.

    8. Re:Here's what TDD would have really done by dkf · · Score: 1

      In TDD, you actually let the tests drive the development. You first write a test, then the simplest code that will satisfy it. Then add more tests/assertions and modify the code.

      The problem with test suites is determining when you have tests that cover everything they need to. I suspect that it is actually a problem equivalent to constructing a formal proof of correctness of the specification and of conformance of the implementation to the spec. (I've always found it necessary to have some tests that are driven by knowledge of the implementation, just to ensure that tricky emergent issues stay fixed.)

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    9. Re:Here's what TDD would have really done by SuperKendall · · Score: 1

      Another problem. You write the test to cover all of the edge cases.

      Except that as I said, very likely that edge case would not have been included.

      The problem with TDD proponents is that they live in a world where every test gets 100% real-world input coverage. Simply put, that's not what happens.

      As I already stated in another message the ordering of test/code was accidental as I was basically copying the list - in the rest of my message you can find the dangers of writing the test first.

      --
      "There is more worth loving than we have strength to love." - Brian Jay Stanley
    10. Re:Here's what TDD would have really done by obarel · · Score: 1

      Some guy somewhere (I say 'guy' because women write perfect code) sat down and wrote this function.

      Now, I don't know the guy, but I'm assuming that he was trying a few values and checking that they make sense.

      The *same* guy, with TDD, would have written exactly the same tests before he coded the function - a few random values just to see that they make sense. TDD wouldn't have transformed him into something he isn't.

      The point is, if he could have written tests that go through all the edge cases, or tested every day from 1980 to 2500, he would have done it with his code, whether before or after writing the function. He didn't, because he couldn't (not saying he's stupid or anything like that - in most cases it's a combination of over-confidence, lack of time and pressure from your boss).

      TDD doesn't make you better. If you can think of all the edge cases, and if it's important enough, you'll write the test either before or after the function and find your bugs. If testing a few cases is enough for you, you wouldn't write better tests just because you write them before you write the function and you make sure they fail first.

      Maybe the reason TDD works for so many people is that by acknowledging they don't know everything, being willing to try a new thing, they simply mature and stop thinking that every line of code they write is gold. Maybe TDD makes you more humble and more mature. But it's not the only way.

      If you don't care about what you write (and no one above you cares, so code reviews are a waste of time and quality assurance is cost) then TDD is not going to change that. The assumption that just because you write the test before you write the function somehow you'll start to care is simply wrong.

      Testing edge cases is not a new thing. Thinking about every 'if' in the code and how to test it is not new either. Making a test fail first and then pass is not some magic - you still have to think about what you do, and most importantly - you still have to care about what you do.

    11. Re:Here's what TDD would have really done by Gorimek · · Score: 1

      TDD made me better. Much better. The discipline of only writing code that is forced out by the tests makes you write more precise tests. The better tests in turn makes you write better code. It takes a while to get into this "upside down" way of thinking.

      "The code doesn't deal with leap years yet, so I'm clearly missing a test" is a quite different mind set from "Let's throw some random dates at it and verify that my code works".

      TDD is not primarily about testing, but a design method. That you end up with a full test suite when the design is done is a very fortunate byproduct, but not the main purpose. Another aspect is that by starting out as a user of the code, you end up producing better APIs. Digressions, I know.

      I don't care more now than I used to, I just use a better engineering practice than I did.

      Nobody said that TDD is the only way, that it transforms you to another person or that it is "some magic". That so many people read fanatical cult proclamations into the humble text I wrote was fascinating.

  49. Braindead comments by Anonymous Coward · · Score: 1, Insightful

    Is it just me or does stuff like this really annoy everyone:

    //Calculate current day of the week
    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.

    1. Re:Braindead comments by Amorya · · Score: 1

      It might have originally had some cryptic maths there, which was later split out into a (sensibly named) function, and they forgot to remove the comment...

  50. When they 'break' 100% many throw it away. by gelfling · · Score: 1

    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.

    1. Re:When they 'break' 100% many throw it away. by ProppaT · · Score: 1

      What the heck are you talking about? There is no DRM on the zune. I upload my plain MP3's everday. The only thing close to DRM is the new Zune service where you can download unlimited DRMed MP3's to your player for $15 a month...which is similar to what other services already offer.

      --
      Wise men say, "Forgiveness is divine, but never pay full price for late pizza."
  51. Re:Old by Anonymous Coward · · Score: 0

    First to finish is not always a good thing. Just ask your girlfriend.

    Obligatory: you forgot that this is Slashdot....

  52. lmao by Anonymous Coward · · Score: 0

    Where are mod points when you need em?

  53. Crap code by gone_bush · · Score: 1

    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)
  54. Never use a while loop in a driver by Anonymous Coward · · Score: 1, Interesting

    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.

    1. Re:Never use a while loop in a driver by Anonymous Coward · · Score: 0

      If you mean while(1), code while(1). Use for() when you want to enumerate something.

      Whether you use for(;;) or while(true) is simply a matter of style. Both are clear and easily read by anyone with even novice familiarity with the programming language being used.

      Never use a while loop in a driver.

      I am not sure that never is always possible. But, yes loops in driver code should be avoided whenever possible.

      Which brings up the issue that in this case, avoiding the loop is possible, as other comments have pointed out. Avoiding using a loop would have resulted in cleaner code; faster code ( O(1) instead of O(n) ); and code which could not possibly result in an infinite loop.

  55. Re:Four is a power of two. Use that fact!!! by Anonymous Coward · · Score: 0

    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).

  56. Unit testing is important. by Anonymous Coward · · Score: 0

    They should have had unit tests that tested every day of the year from 1970 +- 70 years for that function.

  57. Re:Old by Anonymous Coward · · Score: 0

    Don't worry, I'll ask his girlfriend...

  58. And what part of by Master+of+Transhuman · · Score: 1

    "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!
  59. Let's make sure this gets installed everywhere ... by trolltalk.com · · Score: 0, Troll

    " 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?

  60. Re:Old by Anonymous Coward · · Score: 0
    "a lesson to aspiring programmers to watch there step when it comes to timekeeping."

    And yet, the simple there/their/they're thing completely escaped you, and you expect other people to keep track of math?

  61. LOL Algorithms by Khyber · · Score: 1, Insightful

    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.
    1. Re:LOL Algorithms by glindsey · · Score: 1

      Yeah. I mean, it's not like any of those old mainframes running COBOL applications with two-digit year fields were still in use when the year 2000 came around.

      I kid, I kid... I know you were talking about consumer software, but even that's not entirely safe. Bits of code, especially in operating systems, architecture support layers, board support layers, and drivers, have a weird way of sticking around...

  62. That's not TDD by Anonymous Coward · · Score: 0

    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.)

  63. Development tools? by bennomatic · · Score: 1

    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?
    1. Re:Development tools? by stevey · · Score: 1

      All you have to do first is solve the halting problem, and detecting these "clear" cases will be trivial.

    2. Re:Development tools? by bennomatic · · Score: 1

      Thanks for the link; I see your point. However, it seems to me that while it may not be possible to solve for all cases, it shouldn't be impossible to solve for some common and easy-to-spot ones. I haven't read the whole W'pedia entry so please forgive me if there's a flaw in my thinking, but for a bug that seemed so obvious to lots of armchair developers who looked at it, you'd think there'd be some sort of preprocessor which could provide a warning.

      --
      The CB App. What's your 20?
    3. Re:Development tools? by stevey · · Score: 1

      The short version is basically "its easy to spot because we can reason". But to detect it programmatically is non-trivial.

      As you say some bugs are easy to spot via simple analysis - and thats what tools such as "lint" do. They scan source looking for particular classes of bugs, but something like this bug isn't trivial.

    4. Re:Development tools? by bennomatic · · Score: 1

      Understood. Thanks again for the link on the halting problem. Interesting stuff.

      --
      The CB App. What's your 20?
  64. Re:Let's make sure this gets installed everywhere by neokushan · · Score: 4, Insightful

    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
  65. Re:Let's make sure this gets installed everywhere by trolltalk.com · · Score: 0, Flamebait

    "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.

  66. Re:Let's make sure this gets installed everywhere by neokushan · · Score: 4, Informative

    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
  67. Re:Four is a power of two. Use that fact!!! by Poltras · · Score: 1

    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...

  68. Re:Let's make sure this gets installed everywhere by John+Courtland · · Score: 1

    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.
  69. Re:Let's make sure this gets installed everywhere by neokushan · · Score: 1

    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
  70. Re:Let's make sure this gets installed everywhere by gutter · · Score: 4, Insightful

    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
  71. Re:Four is a power of two. Use that fact!!! by celtic_hackr · · Score: 1

    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.

  72. For the people saying "hard to test"... by Anonymous Coward · · Score: 0

    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...

  73. Re:Let's make sure this gets installed everywhere by Hal_Porter · · Score: 1

    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;
  74. Good thing they don't use Windows in Voting machin by goombah99 · · Score: 1

    Oh wait, they do.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  75. Meh Microsoft has a bug by Anonymous Coward · · Score: 0

    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.

  76. so why wasn't this open source bug seen before? by westlake · · Score: 1
    Right, which is why the exact cause of the problem was discovered within hours of the first reports.

    So you telling me that the Zune is the only device that has ever used the Freescale code?

  77. Swoosh! by Anonymous Coward · · Score: 0

    Hand in your geek badge and your Sherlock hat! You sir are not qualified for code review...

  78. Dos ain't done till Netware won't run by Terje+Mathisen · · Score: 3, Informative

    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"
  79. The bug was in converting between day nr and Y-M-D by Terje+Mathisen · · Score: 1

    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"
  80. Re:Let's make sure this gets installed everywhere by Myopic · · Score: 1

    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.

  81. Re:Let's make sure this gets installed everywhere by Myopic · · Score: 1

    how seriously does Microsoft take compatibility?

  82. Re:Old by cerberusss · · Score: 1

    Obligatory xkcd reference.

    --
    8 of 13 people found this answer helpful. Did you?
  83. I did that. by Futurepower(R) · · Score: 1

    I did that. That's how I learned about the web site that has numerous free books.

  84. I know what's wrong by Tablizer · · Score: 1

    they placed "profit" *before* the question marks.
         

  85. Re:Let's make sure this gets installed everywhere by TheLink · · Score: 2, Funny

    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 ;).

    --
  86. Stop blaming QA for lack of fixes by Anonymous Coward · · Score: 0

    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.)

  87. Re:Good thing they don't use Windows in Voting mac by ta+bu+shi+da+yu · · Score: 1

    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.
  88. A simpler reason by kaiwai · · Score: 2, Insightful

    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.

    1. Re:A simpler reason by XO · · Score: 1

      i hate that microwaves only run the standard Microwave OS, too.

      --
      "Champagne for my real friends - and real pain for my sham friends!" http://ericblade.postalboard.com/
    2. Re:A simpler reason by Kilroy · · Score: 1

      It sucks how they won't heat up generic brand food too.

    3. Re:A simpler reason by LeadLine · · Score: 1

      I really don't understand all of this Anti-America stuff on slashdot.

      It might be perfectly appropriate for one to post that somewhere else, and mostly I agree with it; but don't you think most slashdotters from America would rather use the metric system? I mean, you're posting this to an audience of geeks. Maybe should spend your time convincing/mocking somebody that needs/deserves it.

  89. It's called OR by rdnetto · · Score: 2, Interesting

    Couldn't you just do this:


    if((condition1 && condition2) || (issue1 || issue2)){
    //do cleanup
    }

    --
    Most human behaviour can be explained in terms of identity.
  90. Re:Old by sydneyfong · · Score: 1

    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.
  91. Re:Let's make sure this gets installed everywhere by Phoghat · · Score: 1

    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.
  92. Its a good downtime rate! by boltik · · Score: 1

    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.

  93. Re:Four is a power of two. Use that fact!!! by Anonymous Coward · · Score: 0

    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 ) {
                    case 0:
                    break; // if (year divisible by 400) return 1, leap year

                    case 100:
                    case 200:
                    case 300:
                    return 0; // if (year divisible by 100 but not 400) return 0, no leap year

                    default: // if (year not divisible by 100, but by 4) return 1, leap year
            }

            return( 1 );
    }

  94. IT'S A TRAP!!! by SpazmodeusG · · Score: 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.

  95. Leaked source code!? by harlows_monkeys · · Score: 1

    I don't see how the source code being readily available for download from the site of its developer (Freescale) counts as being "leaked".

  96. Re:Let's make sure this gets installed everywhere by vegiVamp · · Score: 1

    > they're once again branded as the most Evil Corporation

    I wasn't aware the designation had been revoked ?

    --
    What a depressingly stupid machine.
  97. From the cubicle in the server room by Gazzonyx · · Score: 2, Funny

    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.

  98. Re:Let's make sure this gets installed everywhere by trolltalk.com · · Score: 1

    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."

  99. Re:Let's make sure this gets installed everywhere by trolltalk.com · · Score: 1

    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.

  100. Re:Let's make sure this gets installed everywhere by Anonymous Coward · · Score: 0

    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".

  101. Re:Let's make sure this gets installed everywhere by db32 · · Score: 4, Insightful

    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.
  102. Re:Four is a power of two. Use that fact!!! by Anonymous Coward · · Score: 0

    A shorter variant:

    int IsLeapYear(int year)

    // if year is not divisible by 4 return 0, isn't leap year

            if ( year & 0x03 ) return 0;

    // if year is divisible by 100 and not is divisible by 16 return 0, isn't leap year
    // 16 is because 16*25=400,75*4=300,8*25=200 and 4*25=100

            if ( ! ( year % 100 ) && ( year & 0x0f ) ) return 0;

    //it's a leap year

            return 1;

            }

    Altenative:

    int IsLeapYear(int year)

    // if year is not divisible by 4 return 0, isn't 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;
    // 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;

    //it's a leap year

            return 1;

            }

  103. Re:Four is a power of two. Use that fact!!! by Anonymous Coward · · Score: 0

    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 & 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;
     
    // if year is not divisible by 100 return 1, it's leap year
    // in the case of year = 400 this stament is never reached
     
    if ( year % 100 ) return 1;
     
    //isn't a leap year
     
    return 0;
     
    }

  104. Re:Four is a power of two. Use that fact!!! by Anonymous Coward · · Score: 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;

  105. Re:Four is a power of two. Use that fact!!! by JackHoffman · · Score: 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.

  106. Re:Let's make sure this gets installed everywhere by neokushan · · Score: 2, Insightful

    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
  107. Re:Let's make sure this gets installed everywhere by neokushan · · Score: 1

    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
  108. crabby answer by roc97007 · · Score: 1

    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.
  109. Re:Let's make sure this gets installed everywhere by Anonymous Coward · · Score: 0

    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.

  110. Re:Let's make sure this gets installed everywhere by Anonymous Coward · · Score: 0

    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.

  111. Re:Let's make sure this gets installed everywhere by db32 · · Score: 1

    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.
  112. Re:Let's make sure this gets installed everywhere by plague3106 · · Score: 1

    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.

  113. Re:Let's make sure this gets installed everywhere by plague3106 · · Score: 1

    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).

  114. Another method by HTH+NE1 · · Score: 1

    int daysThisYear, year = ORIGINYEAR - 1;
     
    // subtract days until you do it once too often
    do {
        days -= ( daysThisYear = 365 + IsLeapYear( ++year ));
    } while( days > 0 );
     
    // then add the last subtraction back
    days += daysThisYear;

    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?
  115. Re:The bug was in converting between day nr and Y- by mevets · · Score: 1

    Dates, despite the enormous historical knowledge of how to treat them, remain a mystery to most computer people.

  116. Re:Let's make sure this gets installed everywhere by Gr8Apes · · Score: 1

    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.
  117. How about actually reading the code, hmm? by Anonymous Coward · · Score: 0

    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...

  118. Sit on a chair by gsgriffin · · Score: 1

    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?
  119. Re:Let's make sure this gets installed everywhere by DiLLeMaN · · Score: 1

    ..., 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.
  120. Re:why not use a standard C library function inste by Tweenk · · Score: 1

    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.
  121. Re:Let's make sure this gets installed everywhere by hesiod · · Score: 1

    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.

  122. Re:Let's make sure this gets installed everywhere by hesiod · · Score: 1

    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?

  123. Re:Old by thetoadwarrior · · Score: 1

    As long as I get mine I could care less if I satisfy your mom.

  124. Re:Let's make sure this gets installed everywhere by db32 · · Score: 1

    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.
  125. Re:Four is a power of two. Use that fact!!! by Marillion · · Score: 1

    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
  126. Obligatory XKCD by Anonymous Coward · · Score: 0

    http://xkcd.com/292/

    "I could restructure the programs flow | or use one little 'goto' instead | How bad can it be?"

  127. Re:Let's make sure this gets installed everywhere by neokushan · · Score: 1

    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
  128. Re:Let's make sure this gets installed everywhere by Gr8Apes · · Score: 1

    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.