Skip to content

Commit

Permalink
refactor: remove extra nil check causing static analysis warning
Browse files Browse the repository at this point in the history
The extra check for response != nil before populating volume information
causes a false positive "possible nil dereference" warning. Remove the
second check to remove the warning at CreateCommonStatus
  • Loading branch information
David-T-White committed Jan 19, 2024
1 parent 0a088ba commit 7f44170
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions pkg/api/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (client *Client) ShowVolumes(volume string) ([]common.VolumeObject, *common

response, httpRes, err := client.apiClient.DefaultApi.ShowVolumesNamesGet(client.Ctx, volume).Execute()

if httpRes.StatusCode == http.StatusOK && response != nil {
if httpRes.StatusCode == http.StatusOK && response != nil && err == nil {

// Extract Status resource information
logger.V(4).Info("++ ShowVolumesNamesGet.Status[0]",
Expand All @@ -152,30 +152,25 @@ func (client *Client) ShowVolumes(volume string) ([]common.VolumeObject, *common

logger.V(4).Info("================================================================================")

returnVolumes := []common.VolumeObject{}
status := &common.ResponseStatus{}
if response.Status != nil {
status = CreateCommonStatus(logger, &response.Status)
}
status := CreateCommonStatus(logger, &response.Status)

if response != nil {
for _, v := range response.Volumes {
volume := common.VolumeObject{}
volume.ObjectName = v.GetObjectName()
volume.Blocks = v.GetBlocks()
volume.BlockSize = v.GetBlocksize()
volume.Health = v.GetHealth()
volume.SizeNumeric = v.GetSizeNumeric()
volume.StoragePoolName = v.GetStoragePoolName()
volume.StorageType = v.GetStorageType()
volume.TierAffinity = v.GetTierAffinity()
volume.TotalSize = v.GetTotalSize()
volume.VolumeName = v.GetVolumeName()
volume.VolumeType = v.GetVolumeType()
volume.Wwn = strings.ToLower(v.GetWwn())

returnVolumes = append(returnVolumes, volume)
}
returnVolumes := []common.VolumeObject{}
for _, v := range response.Volumes {
volume := common.VolumeObject{}
volume.ObjectName = v.GetObjectName()
volume.Blocks = v.GetBlocks()
volume.BlockSize = v.GetBlocksize()
volume.Health = v.GetHealth()
volume.SizeNumeric = v.GetSizeNumeric()
volume.StoragePoolName = v.GetStoragePoolName()
volume.StorageType = v.GetStorageType()
volume.TierAffinity = v.GetTierAffinity()
volume.TotalSize = v.GetTotalSize()
volume.VolumeName = v.GetVolumeName()
volume.VolumeType = v.GetVolumeType()
volume.Wwn = strings.ToLower(v.GetWwn())

returnVolumes = append(returnVolumes, volume)
}

return returnVolumes, status, err
Expand Down

0 comments on commit 7f44170

Please sign in to comment.