Skip to content

Commit

Permalink
work/exec throw an error when buildP is negative
Browse files Browse the repository at this point in the history
Fixed a problem where an error would not occur
when a negative value was specified for the p flag.

Fixes #46686
  • Loading branch information
Yuuki77 committed Jul 23, 2021
1 parent 052da57 commit 5173e9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2880,3 +2880,13 @@ func TestMissingCC(t *testing.T) {
t.Error(`clearing "PATH" causes "net" to be stale`)
}
}

// Issue 46686
func TestInvalidValueForFlagP(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempDir("src")
tg.setenv("GOPATH", tg.path("."))
tg.runFail("build", "-p=-1")
}
6 changes: 6 additions & 0 deletions src/cmd/go/internal/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
if cfg.BuildN {
par = 1
}

if par <= 0 {
fmt.Fprintf(os.Stderr, "go: the number of builds should be positive: %v\n", par)
base.SetExitStatus(1)
}

for i := 0; i < par; i++ {
wg.Add(1)
go func() {
Expand Down

0 comments on commit 5173e9a

Please sign in to comment.