Clamp bounds are inverted, so the result is a constant

ID

rust.correctness.clamping_values_cmp_min_cmp

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Logic

Language

Rust

Description

The lower bound of this clamp is greater than the upper bound, so the range is empty and the result never depends on the value being clamped (clamp panics outright). Swap the two bounds.

Rationale

The lower bound of this clamp is greater than the upper bound, so the range is empty and the result never depends on the value being clamped (clamp panics outright). Swap the two bounds.

The following code illustrates the pattern detected by this rule:

use std::cmp;
pub fn inverted_free_functions(value: i32) -> i32 {
    // FLAGGED: Clamp bounds are inverted, so the result is a constant
    cmp::min(cmp::max(value, 100), 0)
}

Remediation

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

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved