Variable assigned to itself

ID

c.correctness.self_assignment

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundant Operation

Language

C / C++

Description

This assignment sets a variable to itself, which has no effect. It is usually a typo (the right-hand side should be a different variable or expression) or leftover code. Remove the redundant assignment or fix the intended operand.

Rationale

This assignment sets a variable to itself, which has no effect. It is usually a typo (the right-hand side should be a different variable or expression) or leftover code. Remove the redundant assignment or fix the intended operand.

The following code illustrates the pattern detected by this rule:

int y = 1;
// FLAGGED: Variable assigned to itself
x = x;

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.