esx: handle missing switch enum cases

Ensure all enum cases are listed in switch statements, or explicitly
cast away enum type where we don't want to list all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-02-14 09:43:59 +00:00
parent 05b39a6843
commit 7c8f1436d0
3 changed files with 14 additions and 13 deletions

View File

@ -3603,10 +3603,9 @@ esxDomainGetSchedulerParametersFlags(virDomainPtr domain,
params[i].value.i = -3; params[i].value.i = -3;
break; break;
case esxVI_SharesLevel_Undefined:
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportEnumRangeError(esxVI_SharesLevel, sharesInfo->level);
_("Shares level has unknown value %d"),
(int)sharesInfo->level);
esxVI_SharesInfo_Free(&sharesInfo); esxVI_SharesInfo_Free(&sharesInfo);
goto cleanup; goto cleanup;
} }

View File

@ -483,7 +483,7 @@ esxVI_SharedCURL_Lock(CURL *handle ATTRIBUTE_UNUSED, curl_lock_data data,
size_t i; size_t i;
esxVI_SharedCURL *shared = userptr; esxVI_SharedCURL *shared = userptr;
switch (data) { switch ((int)data) {
case CURL_LOCK_DATA_SHARE: case CURL_LOCK_DATA_SHARE:
i = 0; i = 0;
break; break;
@ -511,7 +511,7 @@ esxVI_SharedCURL_Unlock(CURL *handle ATTRIBUTE_UNUSED, curl_lock_data data,
size_t i; size_t i;
esxVI_SharedCURL *shared = userptr; esxVI_SharedCURL *shared = userptr;
switch (data) { switch ((int)data) {
case CURL_LOCK_DATA_SHARE: case CURL_LOCK_DATA_SHARE:
i = 0; i = 0;
break; break;
@ -1563,9 +1563,9 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
break; break;
case esxVI_Occurrence_Undefined:
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportEnumRangeError(esxVI_Occurrence, occurrence);
_("Invalid argument (occurrence)"));
goto cleanup; goto cleanup;
} }
} }
@ -2280,9 +2280,10 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
type, root->type); type, root->type);
break; break;
case esxVI_Occurrence_None:
case esxVI_Occurrence_Undefined:
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportEnumRangeError(esxVI_Occurrence, occurrence);
_("Invalid occurrence value"));
break; break;
} }

View File

@ -544,7 +544,7 @@ VIR_LOG_INIT("esx.esx_vi_types");
#define ESX_VI__TEMPLATE__DISPATCH(_actual_type, _actual_type_name, __type, \ #define ESX_VI__TEMPLATE__DISPATCH(_actual_type, _actual_type_name, __type, \
_dispatch, _error_return) \ _dispatch, _error_return) \
switch (_actual_type) { \ switch ((int)_actual_type) { \
_dispatch \ _dispatch \
\ \
case esxVI_Type_##__type: \ case esxVI_Type_##__type: \
@ -690,7 +690,7 @@ VIR_LOG_INIT("esx.esx_vi_types");
return -1; \ return -1; \
} \ } \
\ \
switch (type) { \ switch ((int)type) { \
_dispatch \ _dispatch \
\ \
case esxVI_Type_##__type: \ case esxVI_Type_##__type: \
@ -967,7 +967,7 @@ esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src)
goto failure; goto failure;
} }
switch (src->type) { switch ((int)src->type) {
case esxVI_Type_Boolean: case esxVI_Type_Boolean:
(*dest)->boolean = src->boolean; (*dest)->boolean = src->boolean;
break; break;
@ -1071,7 +1071,7 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType)
(*anyType)->_name = number; \ (*anyType)->_name = number; \
} while (0) } while (0)
switch ((*anyType)->type) { switch ((int)(*anyType)->type) {
case esxVI_Type_Boolean: case esxVI_Type_Boolean:
if (STREQ((*anyType)->value, "true")) { if (STREQ((*anyType)->value, "true")) {
(*anyType)->boolean = esxVI_Boolean_True; (*anyType)->boolean = esxVI_Boolean_True;
@ -1876,6 +1876,7 @@ esxVI_VirtualMachinePowerState_ConvertToLibvirt
case esxVI_VirtualMachinePowerState_Suspended: case esxVI_VirtualMachinePowerState_Suspended:
return VIR_DOMAIN_PAUSED; return VIR_DOMAIN_PAUSED;
case esxVI_VirtualMachinePowerState_Undefined:
default: default:
return VIR_DOMAIN_NOSTATE; return VIR_DOMAIN_NOSTATE;
} }