Skip to content

BUG False positive warning 214 on mutable output buffer parameter #750

@by-not

Description

@by-not

Bug Report: False positive warning 214 on mutable output buffer parameter

Description

The compiler emits warning 214: possibly a "const" array argument was intended on a function parameter that is intentionally mutable — it is used as an output buffer written to by format(). The warning is a false positive because the parameter is never intended to be read-only.


Compiler version

pawncc — compiler (version 3.10.10)


Minimal reproducible example

stock GetPlayerOrgRankName(playerid, dest[], len = sizeof(dest))
{
    if(!IsPlayerInOrg(playerid))
    {
        format(dest, len, "Sin organizacion");
        return false;
    }
    new rank = GetPlayerOrgRank(playerid) - 1;
    format(dest, len, "%s", g_PlayerOrgRanks[playerid][rank]);
    return true;
}

Compiler output:

warning 214: possibly a "const" array argument was intended: "dest"

Expected behavior

No warning should be emitted. dest[] is a write-only output buffer explicitly passed to format() which modifies it. The compiler should recognize that passing an array as a non-const argument to format() (a native function) marks it as modified/mutable, and therefore const is not appropriate.


Actual behavior

The compiler emits warning 214 suggesting dest should be const, which is incorrect — declaring it const would prevent format() from writing into it and break the intended functionality.


Root cause analysis

This appears to be related to the issue described in PR #302 (pawn-lang/compiler): the compiler's flow analysis fails to mark an array symbol as modified when it is passed as a non-const argument to a native function such as format().

In this case:

  1. dest[] is passed directly to format() as the output destination.
  2. format() is a native whose signature accepts a non-const array — meaning it mutates the buffer.
  3. The compiler does not propagate the "modified" flag from the native call back to the dest symbol in the caller's scope.
  4. As a result, the compiler incorrectly concludes that dest is never modified and suggests it be marked const.

Workaround

Adding a dummy write before the format() call suppresses the warning:

dest[0] = EOS; // forces compiler to recognize dest as mutable
format(dest, len, "...");

This should not be necessary and is purely a workaround for this false positive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions