Invalid strconv Argument

ID

go.strconv_invalid_argument

Severity

low

Remediation Complexity

simple

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

correctness, reliability

Description

Reports an out-of-range numeric-base or bit-size literal passed to a parsing or formatting function in strconv. These functions only accept specific values for their base and bitSize arguments.

Rationale

A base must be 0 (auto-detect, for the Parse* functions only) or in the range 2..36; a bitSize must be a valid width for the target type — 32/64 for floats, 64/128 for complex numbers, and 0..64 for integers. A constant value outside the allowed range cannot succeed: it produces a parse error at run time or a formatting that misbehaves, so it is always a bug.

func fn() {
    strconv.ParseFloat("", 16) // FLAW — bitSize must be 32 or 64
    strconv.ParseInt("", 1, 0) // FLAW — base must be 0 or in 2..36
}

Remediation

Pass a base in the supported range (0 or 2..36) and a bitSize valid for the target type.