Redundant return/continue at the end of a function or loop

ID

c.maintainability.omit_redundant_control_flow

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Control Flow

Language

C / C++

Description

This return; at the end of a void function (or continue; at the end of a loop body) is redundant: control already falls off the end there. Remove the trailing statement to reduce noise.

Rationale

This return; at the end of a void function (or continue; at the end of a loop body) is redundant: control already falls off the end there. Remove the trailing statement to reduce noise.

The following code illustrates the pattern detected by this rule:

void trailing_return(int x) {
    printf("%d\n", x);
    // FLAGGED: Redundant return/continue at the end of a function or loop
    return;
}

Remediation

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

Configuration

This detector does not need any configuration.