Spot the error



  • My wife once told me about an error she found in the code that she is working on. Apparently that error had been in the production system for the better part of 7 years.

    enum Status
    {
        NoErr = 0x000000,
        Flag1 = 0x000001,
        Flag2 = 0x000002,
        Flag3 = 0x000004,
        Flag4 = 0x000008,
        Flag5 = 0x000016,
        Flag6 = 0x000032
    };

    If there is a syntax error in the snippet above, it's because I am not good at C, and she told me about that error years ago.



  •  Good thing nobody ever bothers to check for error codes in real, production code.



  •  So, how long has your wife been working on Playstation 3 firmware?



  • 0, 1, 2, 4, 8, 22, 50.



  • @spamcourt said:

    0, 1, 2, 4, 8, 22, 50.
     

     

    Wow! Amazing you found the bug!

    ...



  • @Evo said:

    @spamcourt said:

    0, 1, 2, 4, 8, 22, 50.
     

     

    Wow! Amazing you found the bug!

    ...

     

     

    Do I win a prize or just your eternal eclaim?

     

    Needles to say I will take a photo of your comment, print it and glue it to my table.

     

    I'm a little conflicted because it's only a bug if bit order is important or they are expecting 32 instead of 50, ect, I guess I will just have to take what I can get.....

     

    BTW>>Borrowed account.



  •  rather strange number of bytes, but since it is all zeros i will let you off



  • @Helix said:

     rather strange number of bytes, but since it is all zeros i will let you off

     

     This is what happens when you let HTML jockeys write actual code.

     Three shall be the number bytes in a constant, and the number of the bytes shall be three. Four bytes shalt thou not have, neither shall thou have two, excepting that thou then append a byte to make three. Five bytes is right out.



  • @lscharen said:

    @Helix said:

     rather strange number of bytes, but since it is all zeros i will let you off

     

     This is what happens when you let HTML jockeys write actual code.

     Three shall be the number bytes in a constant, and the number of the bytes shall be three. Four bytes shalt thou not have, neither shall thou have two, excepting that thou then append a byte to make three. Five bytes is right out.

     

     

    i tend to put stuff like this in a format that is int size for the machine, so for 0x00000000 for ARM or 0x0000 for TI MSP430.... but then i write c for embedded device typically without a file system



  • Nice catch. Setting Flag5 will also set off Flag2 and Flag3 if you test for them later, and using AND.

    Total botch.





  • @spamcourt said:

    0, 1, 2, 4, 8, 22, 50.
    I was thinking of it the other way around.

    0, 1, 2, 4, 8, 10, 20.



  • If you're ever in a mood to drive your wife crazy, show her a working program using these as distinct flag values

    /* Use distinct bits for each flag */
    #define FLAG_A 1
    #define FLAG_B 10
    #define FLAG_C 100
    

    :-)



  • @arty said:

    If you're ever in a mood to drive your wife crazy, show her a working program using these as distinct flag values

    /* Use distinct bits for each flag */
    #define FLAG_A 1
    #define FLAG_B 10
    #define FLAG_C 100
    

    :-)

    As long as you don't add

    #define FLAG_D 1000

    it's perfectly fine, and the comment is completely true.



  • Or even:

    #define FLAG_A 00001
    #define FLAG_B 00010
    #define FLAG_C 00100
    #define FLAG_D 01000 // unused
    #define FLAG_E 10000

     And watch the poor maintenance programmer when he tries to use D.



  • @Abdiel said:

    Or even:

    #define FLAG_A 00001
    #define FLAG_B (1 << log10(00010))
    #define FLAG_C (1 << log10(00100))
    #define FLAG_D (1 << log10(01000)) // unused
    #define FLAG_E (1 << log10(10000))

     And watch the poor maintenance programmer when he tries to use D.

    Maintained that for you.



  •  I once had to maintain a piece of code that messed up between hex and decimal in such a way that it only ended up working for 0x50/80. I asked the original developer if he had used that as his test value, and he was dumbstruck how I was able to guess that.


Log in to reply