Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: expanded the compliant solution

...

While the intent of the code may be to assign b to a and test the value of the result for equality to zero, it is very frequently a case of the programmer mistakenly using the assignment operator = instead of the equals operator ==.

...

When the assignment of b to a is not intendedunintended, this conditional block is now executed when a is equal to b.

Code Block
bgColor#ccccff
if (a == b) {
  /* ... */
}

When the assignment is , if fact, intended, this is an alternative the following compliant solution may be used as the programmer intent is clearer:

Code Block
bgColor#ccccff
if ((a = b) == true) {
  /* ... */
}

...

Although it may be preferable to express this same logic as an assignment followed by a conditional:

Code Block
bgColor#ccccff

a = b;
if (a == 0) {
  /* ... */
}

Risk Assessment

Errors of omission can result in unintended program flow.

...