Array parameter declared with a static minimum size

ID

objectivec.maintainability.static_array_param_size

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Api Design

Language

Objective-C

Description

Reports an array parameter written with the C99 static size qualifier - float curve[static 16] - which declares that the caller always passes at least that many elements.

Rationale

The qualifier reads like a bounds check and is not one. It is a promise from the caller to the compiler, and nothing on either side has to verify it: passing a shorter array, or nil, is undefined behaviour that most compilers accept without a word, while the optimiser is now free to assume the pointer is non-null and to prefetch elements the caller never supplied. The syntax is also unfamiliar enough that a reader is likely to take it for a static storage specifier, and it decays to a plain pointer at the call site anyway, so the length it names is not available where the code actually indexes.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Array parameter declared with a `static` minimum size
static void normalise(float coefficients[static 4], float gain) {
    for (int i = 0; i < 4; i++) {
        coefficients[i] *= gain;
    }
}

Remediation

Declare the parameter as a plain pointer and pass the length explicitly as its own parameter, so the callee can check it. Where the length really is fixed, wrap the array in a struct or a typedef of the array type, which does carry the size through the call.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved