Unobserved Append

ID

go.unobserved_append

Severity

high

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

reliability, suspicious

Description

Reports a bare append(s, x) call whose result is discarded — the call is a statement on its own and is not assigned to anything.

Rationale

append may grow the slice into a freshly allocated backing array and always returns a slice header whose length reflects the appended elements. The returned value is the only reliable way to observe the result. When the return value is dropped, the appended element is silently lost (or the caller keeps using a stale, shorter slice) — almost always a forgotten assignment.

// Bad
append(s, 1)        // FLAW — the grown slice is thrown away

// Good
s = append(s, 1)    // OK — result assigned back
t := append(s, 1)   // OK — result captured

Remediation

Assign the result of append back to the slice variable (s = append(s, x)) or capture it in a new variable.