From: Alan Donovan Date: Wed, 14 Feb 2024 22:17:40 +0000 (-0500) Subject: std: fix more nilness findings X-Git-Tag: go1.23rc1~1115 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f8b4653500744da567767b641378193638d4fcf8;p=gostls13.git std: fix more nilness findings (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 Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI --- diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index 2bfe5890da..25acf1ab43 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -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) diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 71a00494ad..0f9c71ab57 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -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) } }) diff --git a/src/runtime/internal/wasitest/tcpecho_test.go b/src/runtime/internal/wasitest/tcpecho_test.go index 11373955f3..bbcea90310 100644 --- a/src/runtime/internal/wasitest/tcpecho_test.go +++ b/src/runtime/internal/wasitest/tcpecho_test.go @@ -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") diff --git a/src/runtime/trace2cpu.go b/src/runtime/trace2cpu.go index 4635662c08..b3b0fb046d 100644 --- a/src/runtime/trace2cpu.go +++ b/src/runtime/trace2cpu.go @@ -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) {