Skip to content

Commit

Permalink
std: fix more nilness findings
Browse files Browse the repository at this point in the history
(found with x/tools/go/analysis/passes/nilness)

Change-Id: I1bdc7811efbecea95608e634f894cb6c656e3a5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/564221
Reviewed-by: Robert Griesemer <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
adonovan committed Feb 26, 2024
1 parent 0fefe41 commit f8b4653
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/go/types/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ func (check *Checker) rangeStmt(inner stmtContext, s *ast.RangeStmt) {
type identType = ast.Ident
identName := func(n *identType) string { return n.Name }
sKey, sValue := s.Key, s.Value
var sExtra ast.Expr = nil
var sExtra ast.Expr = nil // (used only in types2 fork)
isDef := s.Tok == token.DEFINE
rangeVar := s.X
noNewVarPos := inNode(s, s.TokPos)
Expand Down
4 changes: 2 additions & 2 deletions src/os/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,8 +1659,8 @@ func TestCancelErrors(t *testing.T) {
// This test should kill the child process after 1ms,
// To maximize compatibility with existing uses of exec.CommandContext, the
// resulting error should be an exec.ExitError without additional wrapping.
if ee, ok := err.(*exec.ExitError); !ok {
t.Errorf("Wait error = %v; want %T", err, *ee)
if _, ok := err.(*exec.ExitError); !ok {
t.Errorf("Wait error = %v; want *exec.ExitError", err)
}
})

Expand Down
6 changes: 1 addition & 5 deletions src/runtime/internal/wasitest/tcpecho_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,14 @@ func TestTCPEcho(t *testing.T) {
defer subProcess.Process.Kill()

var conn net.Conn
var err error
for {
var err error
conn, err = net.Dial("tcp", host)
if err == nil {
break
}
time.Sleep(500 * time.Millisecond)
}
if err != nil {
t.Log(b.String())
t.Fatal(err)
}
defer conn.Close()

payload := []byte("foobar")
Expand Down
4 changes: 1 addition & 3 deletions src/runtime/trace2cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ func traceCPUSample(gp *g, mp *m, pp *p, stk []uintptr) {
if gp != nil {
hdr[1] = gp.goid
}
if mp != nil {
hdr[2] = uint64(mp.procid)
}
hdr[2] = uint64(mp.procid)

// Allow only one writer at a time
for !trace.signalLock.CompareAndSwap(0, 1) {
Expand Down

0 comments on commit f8b4653

Please sign in to comment.