mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-01 09:32:08 +00:00
cmd/cloner: do not allocate slices when the source is nil
tailcfg.Node zero-value clone equality checks failed when I added a []*foo to the structure, as the zero value and it's clone contained a different slice header. Updates #9377 Updates #9408 Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
committed by
James Tucker
parent
85155ddaf3
commit
1858ad65c8
@@ -24,9 +24,11 @@ func (src *Match) Clone() *Match {
|
||||
dst.IPProto = append(src.IPProto[:0:0], src.IPProto...)
|
||||
dst.Srcs = append(src.Srcs[:0:0], src.Srcs...)
|
||||
dst.Dsts = append(src.Dsts[:0:0], src.Dsts...)
|
||||
dst.Caps = make([]CapMatch, len(src.Caps))
|
||||
for i := range dst.Caps {
|
||||
dst.Caps[i] = *src.Caps[i].Clone()
|
||||
if src.Caps != nil {
|
||||
dst.Caps = make([]CapMatch, len(src.Caps))
|
||||
for i := range dst.Caps {
|
||||
dst.Caps[i] = *src.Caps[i].Clone()
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
@@ -47,9 +49,11 @@ func (src *CapMatch) Clone() *CapMatch {
|
||||
}
|
||||
dst := new(CapMatch)
|
||||
*dst = *src
|
||||
dst.Values = make([]json.RawMessage, len(src.Values))
|
||||
for i := range dst.Values {
|
||||
dst.Values[i] = append(src.Values[i][:0:0], src.Values[i]...)
|
||||
if src.Values != nil {
|
||||
dst.Values = make([]json.RawMessage, len(src.Values))
|
||||
for i := range dst.Values {
|
||||
dst.Values[i] = append(src.Values[i][:0:0], src.Values[i]...)
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
@@ -24,9 +24,11 @@ func (src *Config) Clone() *Config {
|
||||
*dst = *src
|
||||
dst.Addresses = append(src.Addresses[:0:0], src.Addresses...)
|
||||
dst.DNS = append(src.DNS[:0:0], src.DNS...)
|
||||
dst.Peers = make([]Peer, len(src.Peers))
|
||||
for i := range dst.Peers {
|
||||
dst.Peers[i] = *src.Peers[i].Clone()
|
||||
if src.Peers != nil {
|
||||
dst.Peers = make([]Peer, len(src.Peers))
|
||||
for i := range dst.Peers {
|
||||
dst.Peers[i] = *src.Peers[i].Clone()
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user