Function parameter is reassigned

ID

c.maintainability.avoid_reassigning_parameters

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

low

Resource

Control Flow

Language

C / C++

Description

Parameter $P is reassigned inside the function body. Overwriting a parameter loses the caller’s original argument value and makes the code harder to follow (the name no longer means what was passed in). Introduce a local variable for the modified value and leave the parameter unchanged.

Rationale

Parameter $P is reassigned inside the function body. Overwriting a parameter loses the caller’s original argument value and makes the code harder to follow (the name no longer means what was passed in). Introduce a local variable for the modified value and leave the parameter unchanged.

The following code illustrates the pattern detected by this rule:

int f(int count, int limit, int extra)
{
    // FLAGGED: Function parameter is reassigned
    count = count + 1;
    int local = 0;

Remediation

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

Configuration

This detector does not need any configuration.