Skip to content

Commit

Permalink
do not initialize copy's slice if nil in original
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Dec 24, 2021
1 parent 0fdf624 commit e1c8d58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions nomad/node_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,9 +1531,7 @@ func TestClientEndpoint_GetNode(t *testing.T) {
node.StatusUpdatedAt = resp2.Node.StatusUpdatedAt
node.SecretID = ""
node.Events = resp2.Node.Events
if !reflect.DeepEqual(node, resp2.Node) {
t.Fatalf("bad: %#v \n %#v", node, resp2.Node)
}
require.Equal(t, node, resp2.Node)

// assert that the node register event was set correctly
if len(resp2.Node.Events) != 1 {
Expand Down
6 changes: 4 additions & 2 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3064,8 +3064,10 @@ type NodeCpuResources struct {

func (n NodeCpuResources) Copy() NodeCpuResources {
newN := n
newN.ReservableCpuCores = make([]uint16, len(n.ReservableCpuCores))
copy(newN.ReservableCpuCores, n.ReservableCpuCores)
if n.ReservableCpuCores != nil {
newN.ReservableCpuCores = make([]uint16, len(n.ReservableCpuCores))
copy(newN.ReservableCpuCores, n.ReservableCpuCores)
}

return newN
}
Expand Down

0 comments on commit e1c8d58

Please sign in to comment.