Self-assignment¶
ID: cs/self-assignmentKind: problemSecurity severity: Severity: errorPrecision: highTags: - quality - reliability - correctnessQuery suites: - csharp-security-and-quality.qls
Click to see the query in the CodeQL repository
Assigning a variable to itself is redundant and often an indication of a mistake in the code.
Recommendation¶
Check the assignment carefully for mistakes. If the assignment is truly redundant and not simply incorrect then remove it.
Example¶
In this example the programmer clearly intends to assign tothis.i but made a mistake.
classSelfAssignment{privateinti;publicSelfAssignment(inti){i=i;}}