Monday, March 22, 2010

Avoid assignment in if




Avoid assignment in if statement condition (IfAssign.rule)


Description:

This rule checks whether your code has assignment within an if statement condition. This rule is enabled by default.

Benefits:

Legibility and maintainability.

Assignment in the context of an if statement is easily confused with equality.

Example:

void foo(int a, int b) {

  if ( a = b ) {}  // Violation

}

Repair:

void foo(int a, int b) {

  if ( a == b ) {} // OK
}

Author
ParaSoft




No comments:

Post a Comment

Labels