Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various small issues revealed by staticcheck #2857

Merged
merged 7 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ipam/allocator.go
Expand Up @@ -210,9 +210,9 @@ func (alloc *Allocator) doOperation(op operation, ops *[]operation) {
// already succeeded. If it is on the queue, we call
// cancel on it, allowing callers waiting for the resultChans
// to unblock.
func (alloc *Allocator) cancelOp(op operation, ops *[]operation) {
func (alloc *Allocator) cancelOp(opToCancel operation, ops *[]operation) {
for i, op := range *ops {
if op == op {
if op == opToCancel {
*ops = append((*ops)[:i], (*ops)[i+1:]...)
op.Cancel()
break
Expand Down
1 change: 1 addition & 0 deletions ipam/allocator_test.go
Expand Up @@ -186,6 +186,7 @@ func TestAllocatorClaim(t *testing.T) {
alloc.Prime()
// Do an allocate on the other peer, which we will try to claim later
addrx, err := allocs[0].Allocate(container1, subnet, true, returnFalse)
require.NoError(t, err)
// Should not get the address we pre-claimed
require.NotEqual(t, addrx, preAddr)
router.Flush()
Expand Down
6 changes: 4 additions & 2 deletions ipam/space/space_test.go
Expand Up @@ -52,12 +52,12 @@ func TestLowlevel(t *testing.T) {

s := New()
require.Equal(t, address.Count(0), s.NumFreeAddresses())
ok, got := s.Allocate(address.NewRange(0, 1000))
ok, _ := s.Allocate(address.NewRange(0, 1000))
require.False(t, ok, "allocate in empty space should fail")

s.Add(100, 100)
require.Equal(t, address.Count(100), s.NumFreeAddresses())
ok, got = s.Allocate(address.NewRange(0, 1000))
ok, got := s.Allocate(address.NewRange(0, 1000))
require.True(t, ok && got == 100, "allocate")
require.Equal(t, address.Count(99), s.NumFreeAddresses())
require.NoError(t, s.Claim(150))
Expand All @@ -68,6 +68,7 @@ func TestLowlevel(t *testing.T) {
wt.AssertErrorInterface(t, (*error)(nil), s.Free(100), "double free")

r, ok := s.Donate(address.NewRange(0, 1000))
require.True(t, ok, "donate")
require.Equal(t, address.NewRange(0xa0, 0x20), r, "donate")

// test Donate when addresses are scarce
Expand All @@ -78,6 +79,7 @@ func TestLowlevel(t *testing.T) {
require.NoError(t, s.Claim(0))
require.NoError(t, s.Claim(2))
r, ok = s.Donate(address.NewRange(0, 1000))
require.True(t, ok, "donate")
require.Equal(t, address.NewRange(1, 1), r, "donate")
r, ok = s.Donate(address.NewRange(0, 1000))
require.True(t, !ok, "donate should fail")
Expand Down
2 changes: 1 addition & 1 deletion prog/plugin/main.go
Expand Up @@ -94,7 +94,7 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre
}
go serveStatus(statusListener)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGTERM)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

select {
case sig := <-sigChan:
Expand Down
1 change: 0 additions & 1 deletion prog/weaveutil/docker_tls_args.go
Expand Up @@ -45,7 +45,6 @@ func dockerTLSArgs(args []string) error {
switch {
case arg == "-d" || arg == "daemon":
isDaemon = true
break
case arg == "--tls", arg == "--tlsverify":
tlsArgs = append(tlsArgs, arg)
case strings.HasPrefix(arg, "--tls"):
Expand Down
2 changes: 1 addition & 1 deletion prog/weaveutil/unique_id.go
Expand Up @@ -16,6 +16,6 @@ func uniqueID(args []string) error {
if err != nil {
return err
}
fmt.Printf(uid)
fmt.Print(uid)
return nil
}
8 changes: 5 additions & 3 deletions router/sleeve.go
Expand Up @@ -6,7 +6,6 @@
package router

import (
"bytes"
"encoding/binary"
"fmt"
"io"
Expand Down Expand Up @@ -1039,6 +1038,9 @@ func (sender *udpSenderDF) dial() error {
laddr := &net.IPAddr{IP: sender.localIP}
raddr := &net.IPAddr{IP: sender.remoteIP}
s, err := net.DialIP("ip4:UDP", laddr, raddr)
if err != nil {
return err
}

f, err := s.File()
if err != nil {
Expand All @@ -1059,7 +1061,7 @@ func (sender *udpSenderDF) dial() error {

func (sender *udpSenderDF) send(msg []byte, raddr *net.UDPAddr) error {
// Ensure we have a socket sending to the right IP address
if sender.socket == nil || !bytes.Equal(sender.remoteIP, raddr.IP) {
if sender.socket == nil || !sender.remoteIP.Equal(raddr.IP) {
sender.remoteIP = raddr.IP
if err := sender.dial(); err != nil {
return err
Expand Down Expand Up @@ -1111,7 +1113,7 @@ func (sender *udpSenderDF) close() error {
}

func udpAddrsEqual(a *net.UDPAddr, b *net.UDPAddr) bool {
return bytes.Equal(a.IP, b.IP) && a.Port == b.Port && a.Zone == b.Zone
return a.IP.Equal(b.IP) && a.Port == b.Port && a.Zone == b.Zone
}

func allZeros(s []byte) bool {
Expand Down