From 3398401c06cea82e7de4273c5b656ecb88613c9a Mon Sep 17 00:00:00 2001 From: tanjing2020 Date: Mon, 16 Nov 2020 11:37:47 +0800 Subject: [PATCH] fix staticcheck:pkg/volume/testing pkg/volume/testing/testing.go:417:16: possible nil pointer derefence (SA5011) --- hack/.staticcheck_failures | 1 - pkg/volume/testing/testing.go | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index bcce9fc1e87..073012b03c7 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -1,7 +1,6 @@ cluster/images/etcd/migrate pkg/controller/replicaset pkg/kubelet/dockershim -pkg/volume/testing test/e2e/autoscaling test/integration/examples test/integration/framework diff --git a/pkg/volume/testing/testing.go b/pkg/volume/testing/testing.go index 2b466cc4367..a1b1a14d50d 100644 --- a/pkg/volume/testing/testing.go +++ b/pkg/volume/testing/testing.go @@ -414,14 +414,16 @@ var _ DeviceMountableVolumePlugin = &FakeVolumePlugin{} var _ NodeExpandableVolumePlugin = &FakeVolumePlugin{} func (plugin *FakeVolumePlugin) getFakeVolume(list *[]*FakeVolume) *FakeVolume { - volumeList := *list - if list != nil && len(volumeList) > 0 { - volume := volumeList[0] - volume.Lock() - defer volume.Unlock() - volume.WaitForAttachHook = plugin.WaitForAttachHook - volume.UnmountDeviceHook = plugin.UnmountDeviceHook - return volume + if list != nil { + volumeList := *list + if len(volumeList) > 0 { + volume := volumeList[0] + volume.Lock() + defer volume.Unlock() + volume.WaitForAttachHook = plugin.WaitForAttachHook + volume.UnmountDeviceHook = plugin.UnmountDeviceHook + return volume + } } volume := &FakeVolume{ WaitForAttachHook: plugin.WaitForAttachHook, @@ -430,7 +432,9 @@ func (plugin *FakeVolumePlugin) getFakeVolume(list *[]*FakeVolume) *FakeVolume { volume.VolumesAttached = make(map[string]types.NodeName) volume.DeviceMountState = make(map[string]string) volume.VolumeMountState = make(map[string]string) - *list = append(*list, volume) + if list != nil { + *list = append(*list, volume) + } return volume }