22

Today at work I found this in the code...

if (argCount < 2 && argCount > 3) {
// log invalid arg count
return;
}

And this passed code inspection and has been sitting there unnoticed for about a year and a half... 😂

Whether it's mixing up and with or, or forgetting a semicolon, we've all done it at some point! 😊

Comments
  • 2
    if its not broken, dont fix it... haha it's a trap
  • 0
    I found some dodgy if statement in our code once just by reviewing it and tidying things up, wasn't enough brackets so it was being evaluated wrong. One of the guys just doesn't like putting in extra brackets.
  • 2
    Or, just throwing this out there, he was <i>really</i> concerned about a number that is somehow simultaneously less than 2 but greater than 3...
  • 0
    Maybe it's a multi threaded environment, and the ArgsBuilder thread keeps changing the shared argsList counter.
  • 1
    So code simply accepts 2 or max 3 arguments.
  • 1
    @dhruv notice the &&...

    Even the obvious sections should be tested, apparently
  • 0
    @andersoyvind you are right. Just noticed them.
Add Comment