From 38224e8b7bb709e3b66203f709d4b59d65b7e0a8 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Fri, 29 Nov 2019 07:17:13 -0800 Subject: [PATCH] vc: Use map built-in accessor to find container in Sandbox#GetContainer Fixes #2289 Signed-off-by: Ted Yu --- virtcontainers/sandbox.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index 1d91057a46..5337564650 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -279,10 +279,8 @@ func (s *Sandbox) GetAllContainers() []VCContainer { // GetContainer returns the container named by the containerID. func (s *Sandbox) GetContainer(containerID string) VCContainer { - for id, c := range s.containers { - if id == containerID { - return c - } + if c, ok := s.containers[containerID]; ok { + return c } return nil }