Tautological IF



  • So, I was given the task to run a test cycle for a chunk of inherited code that does a lot of authentication stuff. This code would receive search and auth requests, and route them properly to either a read-only directory or a read/write directory. The read-only instance didn't have any auth data and was used only to search stuff, so it is very important for auth requests to be properly routed or they will fail.

    You've probably guessed it: the routing was b0rked and nothing worked. The inherited code was some extract from an unknown version, which obviously didn't match whatever was on Production. The original developer long gone, nobody actually knew what this code did, they in fact feared what would happen if the production code were to break down. Which is why they pulled out the unknown code, set up a dev system and fired away on the testing stuff.

    After a couple of hours hacking my way through the debug stuff, I finally found out that some weird function would change the "goto read/write" directive to "goto readonly". The weird thing? This wasn't supposed to happen at all. So I check out this function, and find out this gem (pseudocode used):

    if ($op != AUTH || $op != COMPARE)

             $destination = "readonly";

    This particular piece of code was probably intended to send anything not AUTH or COMPARE to the readonly directory. However, thanks to some wonky programmer, this particular IF clause would always return TRUE! It was simply a matter of swapping out the OR for an AND, and everything started working as intended.

    Given that the remaining code never ever did anything even after fixing the broken IF statement, we mostly concluded that this function wasn't even being called in the production environment.



  • This is one of those rare moments where it is one's duty to gain administrative access to the source control system by all means necessary and shred -z the files where this function is stored.

     

     

    mod: removed pointless fullquote of preceding post. Babbu jegus may sleep soundly once again. -dh



  • @GIR said:

    I'm going to sing the Doom song!

    Do it already! I love that song!



  • @danixdefcon5 said:

    if ($op != AUTH || $op != COMPARE)

             $destination = "readonly";

    This particular piece of code was probably intended to send anything not AUTH or COMPARE to the readonly directory. However, thanks to some wonky programmer, this particular IF clause would always return TRUE! It was simply a matter of swapping out the OR for an AND, and everything started working as intended.

     

    May the curse of deMorgan be visited upon him!

     



  • @derula said:

    @GIR said:
    I'm going to sing the Doom song!

    Do it already! I love that song!

    Six months later...



  • Reminds me so much of my ex-boss (same one with the CASE fixation in the other thread). Any time he tried to implement anything like this I'd have to spend five minutes explaining to him why NOT (A OR B) is the same as (NOT A) AND (NOT B). He'd tend to write (NOT A) OR (NOT B) and then wonder why his query wasn't excluding the invalid cases.

    After a few cycles of this we did progress to the point where he'd call me over as he was writing it and say "I can't remember how this should go, can you tell me?" so I guess that was something of an improvement.



  • @blakeyrat said:

    @derula said:
    @GIR said:
    I'm going to sing the Doom song!

    Do it already! I love that song!

    Six months later...

    Heh, I haven't really watched Invader Zim. Though this is what I thought singing the Doom (theme) song would be.

    As for OP, I've seen "if ($condition || $condition)" too many times - this is a real tautology - as described is a logic error.



  • @Zemm said:

    Though this is what I thought singing the Doom (theme) song would be.

    You found the worst YouTube video ever. Congratulations.

    http://www.youtube.com/watch?v=uf47DQj_2Gg (the actual thing.)



  • @blakeyrat said:

    @Zemm said:
    Though this is what I thought singing the Doom (theme) song would be.

    You found the worst YouTube video ever. Congratulations.

    I beg to differ. Do you not know this video?



  • @GIR said:

    I'm going to sing the Doom song!

    Am I the only one here who saw that and immediately thought of Deekin from NWN?


  • 🚽 Regular

    @derula said:

    I beg to differ. Do you not know this video?
     

    Or hell, any FRED video in existance.



  • @Mason Wheeler said:

    @GIR said:

    I'm going to sing the Doom song!

    Am I the only one here who saw that and immediately thought of Deekin from NWN?

    Considering the user name is GIR, a Invader Zim character, and considering it refers to the Doom song, one of the most famous Invader Zim jokes from the pilot episode of Invader Zim and considering danixdefcon5's icon is the character of Invader Zim from a show called "Invader Zim"... yes, yes, you probably are the only one.



  • But what if AUTH == COMPARE?



  • @blakeyrat said:

    @Mason Wheeler said:

    @GIR said:

    I'm going to sing the Doom song!

    Am I the only one here who saw that and immediately thought of Deekin from NWN?

    Considering the user name is GIR, a Invader Zim character, and considering it refers to the Doom song, one of the most famous Invader Zim jokes from the pilot episode of Invader Zim and considering danixdefcon5's icon is the character of Invader Zim from a show called "Invader Zim"... yes, yes, you probably are the only one.

     

    Ah, that would explain it.  I never watched Invader Zim. :P

     



  • @Mason Wheeler said:

    I never watched Invader Zim. :P

    :O



  • @Mason Wheeler said:

    Ah, that would explain it.  I never watched Invader Zim. :P

    Never watched Invader Zim? HAVE YOU THE BRAIN WORMS!?



  • @blakeyrat said:

    @Mason Wheeler said:
    Ah, that would explain it.  I never watched Invader Zim. :P

    Never watched Invader Zim? HAVE YOU THE BRAIN WORMS!?

     

    Nah.  I just don't watch very much TV in general.



  • @Mason Wheeler said:

    @blakeyrat said:

    @Mason Wheeler said:
    Ah, that would explain it.  I never watched Invader Zim. :P
    Never watched Invader Zim? HAVE YOU THE BRAIN WORMS!?
     

    Nah.  I just don't watch very much TV in general.

    </Lurk> <Transmision received and decoded> Neither have I seen more than a few minutes of it, for the same reason, so, yes, I thought of Deekin from NWN as well. <Transmion end> <Lurk> <sleep(OO)>


  • @blakeyrat said:

    @Mason Wheeler said:
    Ah, that would explain it.  I never watched Invader Zim. :P

    Never watched Invader Zim? HAVE YOU THE BRAIN WORMS!?

     

    I saw a bit of an episode and didn't like it.

    Too stupid.

     

    Ren & Stimpy, however.

    That shizzle is the bomdiggy.



  • @Mason Wheeler said:

    @blakeyrat said:

    @Mason Wheeler said:

    @GIR said:

    I'm going to sing the Doom song!

    Am I the only one here who saw that and immediately thought of Deekin from NWN?

    Considering the user name is GIR, a Invader Zim character, and considering it refers to the Doom song, one of the most famous Invader Zim jokes from the pilot episode of Invader Zim and considering danixdefcon5's icon is the character of Invader Zim from a show called "Invader Zim"... yes, yes, you probably are the only one.
     

    Ah, that would explain it.  I never watched Invader Zim. :P

    I don't watch TV either, neither do I play NeverwinterNight so Deekin never crossed my mind...


  • ♿ (Parody)

    @serguey123 said:

    @Mason Wheeler said:

    @blakeyrat said:

    @Mason Wheeler said:

    @GIR said:

    I'm going to sing the Doom song!

    Am I the only one here who saw that and immediately thought of Deekin from NWN?

    Considering the user name is GIR, a Invader Zim character, and considering it refers to the Doom song, one of the most famous Invader Zim jokes from the pilot episode of Invader Zim and considering danixdefcon5's icon is the character of Invader Zim from a show called "Invader Zim"... yes, yes, you probably are the only one.
     

    Ah, that would explain it.  I never watched Invader Zim. :P

    I don't watch TV either, neither do I play NeverwinterNight so Deekin never crossed my mind...

    I never would have guessed that NWN meant NeverwinterNight, either (that's some sort of video game, right?). Several things finally started making sense (well, at least they have an explanation) after this thread. As someone who currently has a 4 year old living in his house, my favorite video on this thread is definitely the dad with the water pistol. His musical abilities are certainly no worse than mine, though my 4 year old is more likely to be up at 5:30 than sleep until 9:30.



  •  @Zemm said:

    As for OP, I've seen "if ($condition || $condition)" too many times - this is a real tautology - as described is a logic error.

    This particular case of !A OR !B turns into a tautology because of the nature of the input. You can get the following situations:

    It's A

    It's B

    It's something else (not A or B)

    So when you build the truth table, you find out that the only condition where the expression would be false is if $op were A and B at the same time, which is impossible. Therefore, it's always true.

    Oh, an extra fun fact: the following code that never got called? It didn't return the correct value, so it would cause the request to fail. We had to stick an else which returned the correct value ... which means that nothing ever goes through the dead code. I wonder how many gems like this are on the production code...

    @serguey123 said:

    I don't watch TV either, neither do I play NeverwinterNight so Deekin never crossed my mind...

    So that's what NWN means! Haven't played D&D computer games, at least the official ones. That's already covered by MUDs, or some MMORPGs. I have read the Dark Elf series, but that might be the extent of my D&D universe knowledge.


Log in to reply