Impossible GOOS Or GOARCH Comparison

ID

go.impossible_goos_goarch

Severity

low

Remediation Complexity

simple

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

CWE:570, reliability, suspicious

Description

Reports a comparison of runtime.GOOS or runtime.GOARCH against a string literal that is not a valid value for that target field.

Rationale

Go ships a fixed set of recognised operating systems and architectures. Comparing the target field against a value outside that set — a typo like "windwos", or a name Go never defines like "x86" — can never be true, so the branch is dead. The check matches only the package-qualified runtime.GOOS / runtime.GOARCH against a verbatim string literal.

import "runtime"

func fn() {
    if runtime.GOOS == "windwos" { // FLAW — typo, no such GOOS
    }
    if runtime.GOOS == "linux" { // OK — a known value
    }
}

Remediation

Correct the literal to a value Go actually defines, or rework the condition.