]> Cypherpunks repositories - gostls13.git/commitdiff
std: fix more nilness findings
authorAlan Donovan <adonovan@google.com>
Wed, 14 Feb 2024 22:17:40 +0000 (17:17 -0500)
committerAlan Donovan <adonovan@google.com>
Mon, 26 Feb 2024 22:01:11 +0000 (22:01 +0000)
(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 <gri@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/go/types/stmt.go
src/os/exec/exec_test.go
src/runtime/internal/wasitest/tcpecho_test.go
src/runtime/trace2cpu.go

index 2bfe5890da9e9ac82996dcddf23149929a868904..25acf1ab437c825c2bb0fb14b2cb65cb55f410e1 100644 (file)
@@ -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)
index 71a00494ad3bbefd942ac8ca7c8be832810c26b4..0f9c71ab57a6e9018d2f4e0e0f60375eab63c553 100644 (file)
@@ -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)
                }
        })
 
index 11373955f34c9d8b83c0c107cbdd94dde7bad28c..bbcea9031069149a82a4cdbe71a94ad0bd27fd91 100644 (file)
@@ -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")
index 4635662c08d56a2615507c30e545cbd2d7537a85..b3b0fb046d82b66e31b6e8463f008a746cddc1e8 100644 (file)
@@ -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) {