8000 Detect ineffectual append(cmd.Env, ...) · Issue #1689 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

Detect ineffectual append(cmd.Env, ...) #1689

Open

Description

@FiloSottile

os/exec.Command returns a Cmd with only Path and Args filled out.

That means that doing

cmd := exec.Command("foo")
cmd.Env = append(cmd.Env, "FOO=bar")

is always equivalent to

cmd := exec.Command("foo")
cmd.Env = []string{"FOO=bar"}

but almost certainly intended to be

cmd := exec.Command("foo")
cmd.Env = append(cmd.Environ(), "FOO=bar")

instead.

I introduced this bug at least a couple times in the standard library tests.

Activity

  1. added and removed
    needs-triageNewly filed issue that needs triage
    on Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment 43BE

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0