If OS = MACOS then DontCrash()



  • #ifdef __OSMAC__
          i = findOperatorIndex(target,0,MAXNAMES-1);
    #else
          i = findOperatorIndex(target,0,MAXNAMES);
    #endif
    

    Just found this code. findOperatorIndex() is a function that performs a binary search of a static global array for a given string. It takes three parameters: 1) the string to search for, 2) the first array index, and 3) the last array index. The array is zero-indexed and contains MAXNAMES elements, and neither the contents nor the length of the array differ between operating systems. Passing MAXNAMES leads to the code walking off the end of the array in certain cases.



    As a second WTF, there's no reason why findOperatorIndex() needs the second and third parameters: the function isn't recursive, the length of the array it's searching is globally known, and searching subsets of the array makes no sense.



    As a bonus, this code has been shipping for at least a decade and a half.



  • Sounds like a piece of embedded software I helped with this week. The code has been working fine for the past 4 years until someone added a new variable - since the code using that variable was very simple, they assumed it wouldn't do anything bad and released it to production with sign off. Since then the application randomly crashes, and the engineer couldn't work why his modification had made it so unreliable. 

    Turned out that the linker was given completely incorrect information from day 1 - 32KBytes of RAM, when in actual effect, the processor used only has 4KB, so a number of variables were at addresses that didn't exist, and adding a further one caused the linker to reshuffle the others around to ensure alignment of various structures. 



  •  I LOLed.  +1 front page material.  (Now all you need is an over-elaborate and typo-peppered backstory and you're away!)




  • @DaveK said:

     I LOLed.  +1 front page material.  (Now all you need is an over-elaborate and typo-peppered backstory and you're away!)

    You mean I have to come up with that, too?!  In that case, other than putting my name in bold, what does Alex do, exactly?


  •  I would guess that the second version was the original, and just happened to work fine because the specific compiler in use at the time generated code that didn't crash when accessing one past the end of that array.  Then the program was ported to MacOS and the compiler there generated code that did crash.  And someone jumped to the conclusion that while the original was obviously valid C (because it didn't crash!), for some reason Macs had stricter requirements ...



  • @bstorer said:

    You mean I have to come up with that, too?!  In that case, other than putting my name in bold, what does Alex do, exactly?

     

     

    bstorer

    Why wait for Alex?



  • @ais523 said:

    @bstorer said:

    You mean I have to come up with that, too?!  In that case, other than putting my name in bold, what does Alex do, exactly?

     

     

    bstorer

    Why wait for Alex?

    How the hell did you do that?!  IT'S WITCHCRAFT, I TELL YOU!



  • @bstorer said:

    @DaveK said:

     I LOLed.  +1 front page material.  (Now all you need is an over-elaborate and typo-peppered backstory and you're away!)

    You mean I have to come up with that, too?!  In that case, other than putting my name in bold, what does Alex do, exactly?
    Puts up with us?




  • @DaveK said:

    Puts up with us?

    I thought the deal was that we get to use the site in return for putting up with his "writing".



  • I don't see the WTF. Fixing the bug for all platforms would have caused a re-test and re-deployment. If the code, including bug, passed QA, was deployed, and no problems were reported, it may have been judged to be more risk than it was worth to change it. Especially if the platforms for which OSMAC is false have not been released in a good long while. What would be the point of changing the code, completely retesting, re-deploying, and informing customers of a bug that wasn't even affecting them anyway?

    (If any of you are about to say "What could possibly go wrong by fixing this bug," then you haven't been in this industry long enough)

    As developers, of course we want to fix all bugs that we find. From a business standpoint it doesn't always make sense. This "WTF" is a good example of the "minimal necessary change" principle. A crash was discovered on platform OSMAC, and it was fixed on platform OSMAC. Whether it is a good application of the rule in this particular case, we cannot know.



  • I (we?) would have fixed the fault, but not retested or redeployed until the next service interval containing other fixes or features. You don't need to inform customers about every change. I know we have several software projects which have internal fixes like the above, but we don't distribute them unless either someone complains, or the next service interval, whichever comes first. 

    (A 'service interval' is defined as a yearly update. Customers pay an annual maintanance fee and get the latest version back as a result, even if its the same version as they have already. CD/DVD only, No packaging or manuals.)



  • @tOmcOlins said:

    @DaveK said:
    Puts up with us?

    I thought the deal was that we get to use the site in return for putting up with his "writing".

      And so we circle each other in a spiral of ever-deepening degradation.  It's the perfect lose-lose outcome for all of us!



Log in to reply