mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: fix linting S1016 (staticcheck) false positive
Staticcheck is suggesting to cast the type or to directly copy, but
doesn't account for nat.SortPortMap mutating the second argument, so
mutating the HostConfig.PortBindings. From the code, it looks like the
intent here was to prevent that (creating a deep copy), so let's keep
that.
daemon/container_operations.go:109:39: S1016: should convert bb (type github.com/docker/docker/vendor/github.com/docker/go-connections/nat.PortBinding) to github.com/docker/docker/vendor/github.com/moby/moby/api/types/container.PortBinding instead of using struct literal (staticcheck)
bindings[p] = append(bindings[p], containertypes.PortBinding{
^
daemon/network.go:952:39: S1016: should convert bb (type github.com/docker/docker/vendor/github.com/docker/go-connections/nat.PortBinding) to github.com/docker/docker/vendor/github.com/moby/moby/api/types/container.PortBinding instead of using struct literal (staticcheck)
bindings[p] = append(bindings[p], containertypes.PortBinding{
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -101,17 +101,14 @@ func buildSandboxOptions(cfg *config.Config, ctr *container.Container) ([]libnet
|
||||
}
|
||||
}
|
||||
|
||||
// Create a deep copy (as [nat.SortPortMap] mutates the map).
|
||||
// Not using a maps.Clone here, as that won't dereference the
|
||||
// slice (PortMap is a map[Port][]PortBinding).
|
||||
bindings := make(containertypes.PortMap)
|
||||
if ctr.HostConfig.PortBindings != nil {
|
||||
for p, b := range ctr.HostConfig.PortBindings {
|
||||
bindings[p] = []containertypes.PortBinding{}
|
||||
for _, bb := range b {
|
||||
bindings[p] = append(bindings[p], containertypes.PortBinding{
|
||||
HostIP: bb.HostIP,
|
||||
HostPort: bb.HostPort,
|
||||
})
|
||||
}
|
||||
}
|
||||
for p, b := range ctr.HostConfig.PortBindings {
|
||||
copied := make([]containertypes.PortBinding, len(b))
|
||||
copy(copied, b)
|
||||
bindings[p] = copied
|
||||
}
|
||||
|
||||
// TODO(thaJeztah): Move this code to a method on nat.PortSet.
|
||||
|
||||
Reference in New Issue
Block a user