0

I have found several instances of bugs like this in dusty corners of our automation code base. Fortunately the person responsible for snippets like these has no longer with the company, but I'd like to warn my coworkers to watch out for it in code reviews.

var NumberList = new List<int>() {1, 2, 3, 11, 4, 5, 6, 7};
bool AllNumbersLessThanTen = true;
foreach (var number in NumberList)
{
    if (number >= 10)
        AllNumbersLessThanTen = false;
    else
        AllNumbersLessThanTen = true;
}

In the above snippet AllNumbersLessThanTen is set to true at the end of the loop because on the last iteration since 7 >= 10 evaluates to false we go to the else statement which assigns AllNumbersLessThanTen, even though 11 is obviously not less than ten. The resulting boolean flag is invalid. The obvious fix is to delete the else and associated code block.

Is there a common name or way to describe this type of bug in QA or software development parlance I could use when writing or discussing bugs of this nature?

2

I'd say it's enough to call it a logic error.

In computer programming, a logic error is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally (or crash). A logic error produces unintended or undesired output or other behaviour, although it may not immediately be recognized as such.

Text above taken from: https://en.wikipedia.org/wiki/Logic_error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.