From 3ed2ed88182b30dbf63c87a66460155537725007 Mon Sep 17 00:00:00 2001 From: Rob Murray Date: Thu, 29 Feb 2024 23:15:53 +0000 Subject: [PATCH] Replace uses of slices.Clone() Avoid https://github.com/golang/go/issues/64759 Co-authored-by: Bjorn Neergaard Signed-off-by: Rob Murray --- libnetwork/internal/resolvconf/resolvconf.go | 12 +++++------- libnetwork/internal/resolvconf/resolvconf_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libnetwork/internal/resolvconf/resolvconf.go b/libnetwork/internal/resolvconf/resolvconf.go index 6e49c37927fd0..0fe35a9bcb479 100644 --- a/libnetwork/internal/resolvconf/resolvconf.go +++ b/libnetwork/internal/resolvconf/resolvconf.go @@ -18,13 +18,11 @@ import ( "bufio" "bytes" "context" - _ "embed" "fmt" "io" "io/fs" "net/netip" "os" - "slices" "strconv" "strings" "text/template" @@ -141,7 +139,7 @@ func (rc *ResolvConf) SetHeader(c string) { // NameServers returns addresses used in nameserver directives. func (rc *ResolvConf) NameServers() []netip.Addr { - return slices.Clone(rc.nameServers) + return append([]netip.Addr(nil), rc.nameServers...) } // OverrideNameServers replaces the current set of nameservers. @@ -152,7 +150,7 @@ func (rc *ResolvConf) OverrideNameServers(nameServers []netip.Addr) { // Search returns the current DNS search domains. func (rc *ResolvConf) Search() []string { - return slices.Clone(rc.search) + return append([]string(nil), rc.search...) } // OverrideSearch replaces the current DNS search domains. @@ -169,7 +167,7 @@ func (rc *ResolvConf) OverrideSearch(search []string) { // Options returns the current options. func (rc *ResolvConf) Options() []string { - return slices.Clone(rc.options) + return append([]string(nil), rc.options...) } // Option finds the last option named search, and returns (value, true) if @@ -192,7 +190,7 @@ func (rc *ResolvConf) Option(search string) (string, bool) { // OverrideOptions replaces the current DNS options. func (rc *ResolvConf) OverrideOptions(options []string) { - rc.options = slices.Clone(options) + rc.options = append([]string(nil), options...) rc.md.NDotsFrom = "" if _, exists := rc.Option("ndots"); exists { rc.md.NDotsFrom = "override" @@ -314,7 +312,7 @@ func (rc *ResolvConf) TransformForIntNS( } rc.md.Transform = "internal resolver" - return slices.Clone(rc.md.ExtNameServers), nil + return append([]ExtDNSEntry(nil), rc.md.ExtNameServers...), nil } // Generate returns content suitable for writing to a resolv.conf file. If comments diff --git a/libnetwork/internal/resolvconf/resolvconf_test.go b/libnetwork/internal/resolvconf/resolvconf_test.go index 21605178df8cb..94f4ff09c9eeb 100644 --- a/libnetwork/internal/resolvconf/resolvconf_test.go +++ b/libnetwork/internal/resolvconf/resolvconf_test.go @@ -221,15 +221,15 @@ func TestRCModify(t *testing.T) { rc.OverrideSearch(tc.overrideSearch) rc.OverrideOptions(tc.overrideOptions) - assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateComparable(netip.Addr{}))) - assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch)) - assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions)) + assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateEmpty(), cmpopts.EquateComparable(netip.Addr{}))) + assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch, cmpopts.EquateEmpty())) + assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions, cmpopts.EquateEmpty())) } if tc.addOption != "" { options := rc.Options() rc.AddOption(tc.addOption) - assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption))) + assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption), cmpopts.EquateEmpty())) } d := t.TempDir()