Skip to content

Commit

Permalink
Merge pull request #2281 from dbresson/fix-reserved-merge-error
Browse files Browse the repository at this point in the history
avoid a nil pointer dereference
  • Loading branch information
dadgar authored Feb 3, 2017
2 parents 52a4c92 + a49759f commit 6b99276
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 4 additions & 1 deletion command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,10 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
if b.ClientMinPort != 0 {
result.ClientMinPort = b.ClientMinPort
}
if b.Reserved != nil {
if result.Reserved == nil && b.Reserved != nil {
reserved := *b.Reserved
result.Reserved = &reserved
} else if b.Reserved != nil {
result.Reserved = result.Reserved.Merge(b.Reserved)
}
if b.GCInterval != 0 {
Expand Down
24 changes: 20 additions & 4 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ var (
)

func TestConfig_Merge(t *testing.T) {
c0 := &Config{}

c1 := &Config{
Telemetry: &Telemetry{},
Client: &ClientConfig{},
Server: &ServerConfig{},
Ports: &Ports{},
Addresses: &Addresses{},
AdvertiseAddrs: &AdvertiseAddrs{},
Atlas: &AtlasConfig{},
Vault: &config.VaultConfig{},
Consul: &config.ConsulConfig{},
}

c2 := &Config{
Region: "global",
Datacenter: "dc1",
NodeName: "node1",
Expand Down Expand Up @@ -136,7 +150,7 @@ func TestConfig_Merge(t *testing.T) {
},
}

c2 := &Config{
c3 := &Config{
Region: "region2",
Datacenter: "dc2",
NodeName: "node2",
Expand Down Expand Up @@ -271,9 +285,11 @@ func TestConfig_Merge(t *testing.T) {
},
}

result := c1.Merge(c2)
if !reflect.DeepEqual(result, c2) {
t.Fatalf("bad:\n%#v\n%#v", result, c2)
result := c0.Merge(c1)
result = result.Merge(c2)
result = result.Merge(c3)
if !reflect.DeepEqual(result, c3) {
t.Fatalf("bad:\n%#v\n%#v", result, c3)
}
}

Expand Down

0 comments on commit 6b99276

Please sign in to comment.