Code cleanup: remove explicit NULL comparisons like ptr == NULL and ptr != NULL from the ESX code, replacing them with the simpler ptr and !ptr. Part one of three. --- src/esx/esx_driver.c | 244 ++++++++++++------------ src/esx/esx_vi.c | 475 +++++++++++++++++++++++------------------------ src/esx/esx_vi_methods.c | 10 +- src/esx/esx_vi_types.c | 88 ++++----- 4 files changed, 406 insertions(+), 411 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 13423d0..5d8baa5 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -64,7 +64,7 @@ struct _esxVMX_Data { static void esxFreePrivate(esxPrivate **priv) { - if (priv == NULL || *priv == NULL) { + if (!priv || !(*priv)) { return; } @@ -143,7 +143,7 @@ esxParseVMXFileName(const char *fileName, void *opaque) char *copyOfFileName = NULL; char *directoryAndFileName; - if (strchr(fileName, '/') == NULL && strchr(fileName, '\\') == NULL) { + if (!strchr(fileName, '/') && !strchr(fileName, '\\')) { /* Plain file name, use same directory as for the .vmx file */ if (virAsprintf(&result, "%s/%s", data->datastorePathWithoutFileName, fileName) < 0) @@ -157,7 +157,7 @@ esxParseVMXFileName(const char *fileName, void *opaque) } /* Search for datastore by mount path */ - for (datastore = datastoreList; datastore != NULL; + for (datastore = datastoreList; datastore; datastore = datastore->_next) { esxVI_DatastoreHostMount_Free(&hostMount); datastoreName = NULL; @@ -172,7 +172,7 @@ esxParseVMXFileName(const char *fileName, void *opaque) tmp = (char *)STRSKIP(fileName, hostMount->mountInfo->path); - if (tmp == NULL) { + if (!tmp) { continue; } @@ -204,15 +204,15 @@ esxParseVMXFileName(const char *fileName, void *opaque) } /* Fallback to direct datastore name match */ - if (result == NULL && STRPREFIX(fileName, "/vmfs/volumes/")) { + if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { if (VIR_STRDUP(copyOfFileName, fileName) < 0) { goto cleanup; } /* Expected format: '/vmfs/volumes/<datastore>/<path>' */ - if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL || - (datastoreName = strtok_r(tmp, "/", &saveptr)) == NULL || - (directoryAndFileName = strtok_r(NULL, "", &saveptr)) == NULL) { + if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) || + !(datastoreName = strtok_r(tmp, "/", &saveptr)) || + !(directoryAndFileName = strtok_r(NULL, "", &saveptr))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("File name '%s' doesn't have expected format " "'/vmfs/volumes/<datastore>/<path>'"), fileName); @@ -227,7 +227,7 @@ esxParseVMXFileName(const char *fileName, void *opaque) goto cleanup; } - if (datastoreList == NULL) { + if (!datastoreList) { virReportError(VIR_ERR_INTERNAL_ERROR, _("File name '%s' refers to non-existing datastore '%s'"), fileName, datastoreName); @@ -240,14 +240,14 @@ esxParseVMXFileName(const char *fileName, void *opaque) } /* If it's an absolute path outside of a datastore just use it as is */ - if (result == NULL && *fileName == '/') { + if (!result && *fileName == '/') { /* FIXME: need to deal with Windows paths here too */ if (VIR_STRDUP(result, fileName) < 0) { goto cleanup; } } - if (result == NULL) { + if (!result) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not handle file name '%s'"), fileName); goto cleanup; @@ -310,7 +310,7 @@ esxFormatVMXFileName(const char *fileName, void *opaque) } /* Detect separator type */ - if (strchr(hostMount->mountInfo->path, '\\') != NULL) { + if (strchr(hostMount->mountInfo->path, '\\')) { separator = '\\'; } @@ -388,7 +388,7 @@ esxAutodetectSCSIControllerModel(virDomainDiskDefPtr def, int *model, if (def->device != VIR_DOMAIN_DISK_DEVICE_DISK || def->bus != VIR_DOMAIN_DISK_BUS_SCSI || def->type != VIR_DOMAIN_DISK_TYPE_FILE || - def->src == NULL || + !def->src || ! STRPREFIX(def->src, "[")) { /* * This isn't a file-based SCSI disk device with a datastore related @@ -405,7 +405,7 @@ esxAutodetectSCSIControllerModel(virDomainDiskDefPtr def, int *model, vmDiskFileInfo = esxVI_VmDiskFileInfo_DynamicCast(fileInfo); - if (vmDiskFileInfo == NULL || vmDiskFileInfo->controllerType == NULL) { + if (!vmDiskFileInfo || !vmDiskFileInfo->controllerType) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup controller model for '%s'"), def->src); goto cleanup; @@ -466,7 +466,7 @@ esxSupportsLongMode(esxPrivate *priv) goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) { if (esxVI_HostCpuIdInfo_CastListFromAnyType @@ -474,7 +474,7 @@ esxSupportsLongMode(esxPrivate *priv) goto cleanup; } - for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo != NULL; + for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo; hostCpuIdInfo = hostCpuIdInfo->_next) { if (hostCpuIdInfo->level->value == -2147483647) { /* 0x80000001 */ if (esxVI_ParseHostCpuIdInfo(&parsedHostCpuIdInfo, @@ -581,7 +581,7 @@ esxCapsInit(esxPrivate *priv) caps = virCapabilitiesNew(VIR_ARCH_I686, 1, 1); } - if (caps == NULL) + if (!caps) return NULL; virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr"); @@ -597,12 +597,11 @@ esxCapsInit(esxPrivate *priv) NULL, NULL, 0, NULL); - if (guest == NULL) { + if (!guest) { goto failure; } - if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, - NULL) == NULL) { + if (!virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL)) { goto failure; } @@ -613,12 +612,11 @@ esxCapsInit(esxPrivate *priv) NULL, NULL, 0, NULL); - if (guest == NULL) { + if (!guest) { goto failure; } - if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, - NULL) == NULL) { + if (!virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL)) { goto failure; } } @@ -652,7 +650,7 @@ esxConnectToHost(esxPrivate *priv, ? esxVI_ProductVersion_ESX : esxVI_ProductVersion_GSX; - if (vCenterIpAddress == NULL || *vCenterIpAddress != NULL) { + if (!vCenterIpAddress || *vCenterIpAddress) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -661,13 +659,13 @@ esxConnectToHost(esxPrivate *priv, return -1; } - if (conn->uri->user != NULL) { + if (conn->uri->user) { if (VIR_STRDUP(username, conn->uri->user) < 0) goto cleanup; } else { username = virAuthGetUsername(conn, auth, "esx", "root", conn->uri->server); - if (username == NULL) { + if (!username) { virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed")); goto cleanup; } @@ -675,14 +673,14 @@ esxConnectToHost(esxPrivate *priv, unescapedPassword = virAuthGetPassword(conn, auth, "esx", username, conn->uri->server); - if (unescapedPassword == NULL) { + if (!unescapedPassword) { virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed")); goto cleanup; } password = esxUtil_EscapeForXml(unescapedPassword); - if (password == NULL) { + if (!password) { goto cleanup; } @@ -770,8 +768,8 @@ esxConnectToVCenter(esxPrivate *priv, char *password = NULL; char *url = NULL; - if (hostSystemIpAddress == NULL && - (priv->parsedUri->path == NULL || STREQ(priv->parsedUri->path, "/"))) { + if (!hostSystemIpAddress && + (!priv->parsedUri->path || STREQ(priv->parsedUri->path, "/"))) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Path has to specify the datacenter and compute resource")); return -1; @@ -781,14 +779,14 @@ esxConnectToVCenter(esxPrivate *priv, return -1; } - if (conn->uri->user != NULL) { + if (conn->uri->user) { if (VIR_STRDUP(username, conn->uri->user) < 0) { goto cleanup; } } else { username = virAuthGetUsername(conn, auth, "esx", "administrator", hostname); - if (username == NULL) { + if (!username) { virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed")); goto cleanup; } @@ -796,14 +794,14 @@ esxConnectToVCenter(esxPrivate *priv, unescapedPassword = virAuthGetPassword(conn, auth, "esx", username, hostname); - if (unescapedPassword == NULL) { + if (!unescapedPassword) { virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed")); goto cleanup; } password = esxUtil_EscapeForXml(unescapedPassword); - if (password == NULL) { + if (!password) { goto cleanup; } @@ -830,7 +828,7 @@ esxConnectToVCenter(esxPrivate *priv, goto cleanup; } - if (hostSystemIpAddress != NULL) { + if (hostSystemIpAddress) { if (esxVI_Context_LookupManagedObjectsByHostSystemIp (priv->vCenter, hostSystemIpAddress) < 0) { goto cleanup; @@ -913,14 +911,14 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* Decline if the URI is NULL or the scheme is NULL */ - if (conn->uri == NULL || conn->uri->scheme == NULL) { + if (!conn->uri || !conn->uri->scheme) { return VIR_DRV_OPEN_DECLINED; } /* Decline if the scheme is not one of {vpx|esx|gsx} */ plus = strchr(conn->uri->scheme, '+'); - if (plus == NULL) { + if (!plus) { if (STRCASENEQ(conn->uri->scheme, "vpx") && STRCASENEQ(conn->uri->scheme, "esx") && STRCASENEQ(conn->uri->scheme, "gsx")) { @@ -941,20 +939,20 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, } if (STRCASENEQ(conn->uri->scheme, "vpx") && - conn->uri->path != NULL && STRNEQ(conn->uri->path, "/")) { + conn->uri->path && STRNEQ(conn->uri->path, "/")) { VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'", conn->uri->path, conn->uri->scheme); } /* Require server part */ - if (conn->uri->server == NULL) { + if (!conn->uri->server) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("URI is missing the server part")); return VIR_DRV_OPEN_ERROR; } /* Require auth */ - if (auth == NULL || auth->cb == NULL) { + if (!auth || !auth->cb) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Missing or invalid auth pointer")); return VIR_DRV_OPEN_ERROR; @@ -1005,16 +1003,16 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, } /* Connect to vCenter */ - if (priv->parsedUri->vCenter != NULL) { + if (!priv->parsedUri->vCenter) { if (STREQ(priv->parsedUri->vCenter, "*")) { - if (potentialVCenterIpAddress == NULL) { + if (!potentialVCenterIpAddress) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("This host is not managed by a vCenter")); goto cleanup; } - if (virStrcpyStatic(vCenterIpAddress, - potentialVCenterIpAddress) == NULL) { + if (!virStrcpyStatic(vCenterIpAddress, + potentialVCenterIpAddress)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("vCenter IP address %s too big for destination"), potentialVCenterIpAddress); @@ -1026,7 +1024,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, goto cleanup; } - if (potentialVCenterIpAddress != NULL && + if (potentialVCenterIpAddress && STRNEQ(vCenterIpAddress, potentialVCenterIpAddress)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("This host is managed by a vCenter with IP " @@ -1060,7 +1058,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, /* Setup capabilities */ priv->caps = esxCapsInit(priv); - if (priv->caps == NULL) { + if (!priv->caps) { goto cleanup; } @@ -1086,14 +1084,14 @@ esxConnectClose(virConnectPtr conn) esxPrivate *priv = conn->privateData; int result = 0; - if (priv->host != NULL) { + if (priv->host) { if (esxVI_EnsureSession(priv->host) < 0 || esxVI_Logout(priv->host) < 0) { result = -1; } } - if (priv->vCenter != NULL) { + if (priv->vCenter) { if (esxVI_EnsureSession(priv->vCenter) < 0 || esxVI_Logout(priv->vCenter) < 0) { result = -1; @@ -1161,7 +1159,7 @@ esxConnectSupportsFeature(virConnectPtr conn, int feature) } /* Migration is only possible via a vCenter and if VMotion is enabled */ - return priv->vCenter != NULL && + return priv->vCenter && supportsVMotion == esxVI_Boolean_True ? 1 : 0; default: @@ -1222,7 +1220,7 @@ esxConnectGetHostname(virConnectPtr conn) goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.network.dnsConfig.hostName")) { @@ -1245,13 +1243,13 @@ esxConnectGetHostname(virConnectPtr conn) } } - if (hostName == NULL || strlen(hostName) < 1) { + if (!hostName || strlen(hostName) < 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or empty 'hostName' property")); goto cleanup; } - if (domainName == NULL || strlen(domainName) < 1) { + if (!domainName || strlen(domainName) < 1) { if (VIR_STRDUP(complete, hostName) < 0) goto cleanup; } else { @@ -1308,7 +1306,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -1381,9 +1379,9 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) ++ptr; } - if (virStrncpy(nodeinfo->model, dynamicProperty->val->string, - sizeof(nodeinfo->model) - 1, - sizeof(nodeinfo->model)) == NULL) { + if (!virStrncpy(nodeinfo->model, dynamicProperty->val->string, + sizeof(nodeinfo->model) - 1, + sizeof(nodeinfo->model))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("CPU Model %s too long for destination"), dynamicProperty->val->string); @@ -1423,7 +1421,7 @@ esxConnectGetCapabilities(virConnectPtr conn) esxPrivate *priv = conn->privateData; char *xml = virCapabilitiesFormatXML(priv->caps); - if (xml == NULL) { + if (!xml) { virReportOOMError(); return NULL; } @@ -1459,7 +1457,7 @@ esxConnectListDomains(virConnectPtr conn, int *ids, int maxids) goto cleanup; } - for (virtualMachine = virtualMachineList; virtualMachine != NULL; + for (virtualMachine = virtualMachineList; virtualMachine; virtualMachine = virtualMachine->_next) { if (esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { @@ -1539,7 +1537,7 @@ esxDomainLookupByID(virConnectPtr conn, int id) goto cleanup; } - for (virtualMachine = virtualMachineList; virtualMachine != NULL; + for (virtualMachine = virtualMachineList; virtualMachine; virtualMachine = virtualMachine->_next) { if (esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { @@ -1565,7 +1563,7 @@ esxDomainLookupByID(virConnectPtr conn, int id) domain = virGetDomain(conn, name_candidate, uuid_candidate); - if (domain == NULL) { + if (!domain) { goto cleanup; } @@ -1574,7 +1572,7 @@ esxDomainLookupByID(virConnectPtr conn, int id) break; } - if (domain == NULL) { + if (!domain) { virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id); } @@ -1616,7 +1614,7 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) domain = virGetDomain(conn, name, uuid); - if (domain == NULL) { + if (!domain) { goto cleanup; } @@ -1662,7 +1660,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) goto cleanup; } - if (virtualMachine == NULL) { + if (!virtualMachine) { virReportError(VIR_ERR_NO_DOMAIN, _("No domain with name '%s'"), name); goto cleanup; } @@ -1674,7 +1672,7 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) domain = virGetDomain(conn, name, uuid); - if (domain == NULL) { + if (!domain) { goto cleanup; } @@ -1922,7 +1920,7 @@ esxDomainDestroyFlags(virDomainPtr domain, virCheckFlags(0, -1); - if (priv->vCenter != NULL) { + if (priv->vCenter) { ctx = priv->vCenter; } else { ctx = priv->host; @@ -2013,7 +2011,7 @@ esxDomainGetMaxMemory(virDomainPtr domain) goto cleanup; } - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -2224,7 +2222,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) info->state = VIR_DOMAIN_NOSTATE; - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "runtime.powerState")) { if (esxVI_VirtualMachinePowerState_CastFromAnyType @@ -2271,7 +2269,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) #if ESX_QUERY_FOR_USED_CPU_TIME /* Verify the cached 'used CPU time' performance counter ID */ /* FIXME: Currently no host for a vpx:// connection */ - if (priv->host != NULL) { + if (priv->host) { if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) { if (esxVI_Int_Alloc(&counterId) < 0) { goto cleanup; @@ -2312,7 +2310,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) goto cleanup; } - for (perfMetricId = perfMetricIdList; perfMetricId != NULL; + for (perfMetricId = perfMetricIdList; perfMetricId; perfMetricId = perfMetricId->_next) { VIR_DEBUG("perfMetricId counterId %d, instance '%s'", perfMetricId->counterId->value, perfMetricId->instance); @@ -2330,7 +2328,7 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) goto cleanup; } - for (perfCounterInfo = perfCounterInfoList; perfCounterInfo != NULL; + for (perfCounterInfo = perfCounterInfoList; perfCounterInfo; perfCounterInfo = perfCounterInfo->_next) { VIR_DEBUG("perfCounterInfo key %d, nameInfo '%s', groupInfo '%s', " "unitInfo '%s', rollupType %d, statsType %d", @@ -2380,14 +2378,14 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) } for (perfEntityMetricBase = perfEntityMetricBaseList; - perfEntityMetricBase != NULL; + perfEntityMetricBase; perfEntityMetricBase = perfEntityMetricBase->_next) { VIR_DEBUG("perfEntityMetric ..."); perfEntityMetric = esxVI_PerfEntityMetric_DynamicCast(perfEntityMetricBase); - if (perfEntityMetric == NULL) { + if (!perfEntityMetric) { virReportError(VIR_ERR_INTERNAL_ERROR, _("QueryPerf returned object with unexpected type '%s'"), esxVI_Type_ToString(perfEntityMetricBase->_type)); @@ -2397,19 +2395,19 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) perfMetricIntSeries = esxVI_PerfMetricIntSeries_DynamicCast(perfEntityMetric->value); - if (perfMetricIntSeries == NULL) { + if (!perfMetricIntSeries) { virReportError(VIR_ERR_INTERNAL_ERROR, _("QueryPerf returned object with unexpected type '%s'"), esxVI_Type_ToString(perfEntityMetric->value->_type)); goto cleanup; } - for (; perfMetricIntSeries != NULL; + for (; perfMetricIntSeries; perfMetricIntSeries = perfMetricIntSeries->_next) { VIR_DEBUG("perfMetricIntSeries ..."); for (value = perfMetricIntSeries->value; - value != NULL; + value; value = value->_next) { VIR_DEBUG("value %lld", (long long int)value->value); } @@ -2434,11 +2432,11 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) * Remove values owned by data structures to prevent them from being freed * by the call to esxVI_PerfQuerySpec_Free(). */ - if (querySpec != NULL) { + if (querySpec) { querySpec->entity = NULL; querySpec->format = NULL; - if (querySpec->metricId != NULL) { + if (querySpec->metricId) { querySpec->metricId->instance = NULL; } } @@ -2621,7 +2619,7 @@ esxDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -2721,7 +2719,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) data.ctx = priv->primary; - if (directoryName == NULL) { + if (!directoryName) { if (virAsprintf(&data.datastorePathWithoutFileName, "[%s]", datastoreName) < 0) goto cleanup; @@ -2738,7 +2736,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def = virVMXParseConfig(&ctx, priv->xmlopt, vmx); - if (def != NULL) { + if (def) { if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { def->id = id; } @@ -2747,7 +2745,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) } cleanup: - if (url == NULL) { + if (!url) { virBufferFreeAndReset(&buffer); } @@ -2797,7 +2795,7 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, priv->xmlopt, nativeConfig); - if (def != NULL) { + if (def) { xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE); } @@ -2840,7 +2838,7 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, def = virDomainDefParseString(domainXml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, 0); - if (def == NULL) { + if (!def) { return NULL; } @@ -2889,7 +2887,7 @@ esxConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxname goto cleanup; } - for (virtualMachine = virtualMachineList; virtualMachine != NULL; + for (virtualMachine = virtualMachineList; virtualMachine; virtualMachine = virtualMachine->_next) { if (esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { @@ -3057,7 +3055,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE); - if (def == NULL) { + if (!def) { return NULL; } @@ -3068,14 +3066,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; } - if (virtualMachine == NULL && + if (!virtualMachine && esxVI_LookupVirtualMachineByName(priv->primary, def->name, NULL, &virtualMachine, esxVI_Occurrence_OptionalItem) < 0) { goto cleanup; } - if (virtualMachine != NULL) { + if (virtualMachine) { /* FIXME */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Domain already exists, editing existing domains is not " @@ -3101,7 +3099,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) vmx = virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version); - if (vmx == NULL) { + if (!vmx) { goto cleanup; } @@ -3127,14 +3125,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) } } - if (disk == NULL) { + if (!disk) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Domain XML doesn't contain any file-based harddisks, " "cannot deduce datastore and path for VMX file")); goto cleanup; } - if (disk->src == NULL) { + if (!disk->src) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("First file-based harddisk has no source, cannot deduce " "datastore and path for VMX file")); @@ -3156,14 +3154,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) virBufferAsprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport, conn->uri->server, conn->uri->port); - if (directoryName != NULL) { + if (directoryName) { virBufferURIEncodeString(&buffer, directoryName); virBufferAddChar(&buffer, '/'); } escapedName = esxUtil_EscapeDatastoreItem(def->name); - if (escapedName == NULL) { + if (!escapedName) { goto cleanup; } @@ -3191,7 +3189,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) } /* Register the domain */ - if (directoryName != NULL) { + if (directoryName) { if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName, directoryName, escapedName) < 0) goto cleanup; @@ -3221,14 +3219,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) domain = virGetDomain(conn, def->name, def->uuid); - if (domain != NULL) { + if (domain) { domain->id = -1; } /* FIXME: Add proper rollback in case of an error */ cleanup: - if (url == NULL) { + if (!url) { virBufferFreeAndReset(&buffer); } @@ -3267,7 +3265,7 @@ esxDomainUndefineFlags(virDomainPtr domain, * ESX, so we can trivially ignore that flag. */ virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1); - if (priv->vCenter != NULL) { + if (priv->vCenter) { ctx = priv->vCenter; } else { ctx = priv->host; @@ -3346,7 +3344,7 @@ esxDomainGetAutostart(virDomainPtr domain, int *autostart) goto cleanup; } - if (powerInfoList == NULL) { + if (!powerInfoList) { /* powerInfo list is empty, exit early here */ result = 0; goto cleanup; @@ -3358,7 +3356,7 @@ esxDomainGetAutostart(virDomainPtr domain, int *autostart) goto cleanup; } - for (powerInfo = powerInfoList; powerInfo != NULL; + for (powerInfo = powerInfoList; powerInfo; powerInfo = powerInfo->_next) { if (STREQ(powerInfo->key->value, virtualMachine->obj->value)) { if (STRCASEEQ(powerInfo->startAction, "powerOn")) { @@ -3428,7 +3426,7 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) goto cleanup; } - for (powerInfo = powerInfoList; powerInfo != NULL; + for (powerInfo = powerInfoList; powerInfo; powerInfo = powerInfo->_next) { if (STRNEQ(powerInfo->key->value, virtualMachine->obj->value)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -3479,7 +3477,7 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) result = 0; cleanup: - if (newPowerInfo != NULL) { + if (newPowerInfo) { newPowerInfo->key = NULL; newPowerInfo->startAction = NULL; newPowerInfo->stopAction = NULL; @@ -3535,7 +3533,7 @@ esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) if (VIR_STRDUP(type, "allocation") < 0) return NULL; - if (nparams != NULL) { + if (nparams) { *nparams = 3; /* reservation, limit, shares */ } @@ -3575,7 +3573,7 @@ esxDomainGetSchedulerParametersFlags(virDomainPtr domain, } for (dynamicProperty = virtualMachine->propSet; - dynamicProperty != NULL && mask != 7 && i < 3 && i < *nparams; + dynamicProperty && mask != 7 && i < 3 && i < *nparams; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.cpuAllocation.reservation") && ! (mask & (1 << 0))) { @@ -3832,7 +3830,7 @@ esxDomainMigratePrepare(virConnectPtr dconn, virCheckFlags(ESX_MIGRATION_FLAGS, -1); - if (uri_in == NULL) { + if (!uri_in) { if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s", priv->vCenter->ipAddress, priv->vCenter->computeResource->resourcePool->value, @@ -3870,13 +3868,13 @@ esxDomainMigratePerform(virDomainPtr domain, virCheckFlags(ESX_MIGRATION_FLAGS, -1); - if (priv->vCenter == NULL) { + if (!priv->vCenter) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Migration not possible without a vCenter")); return -1; } - if (dname != NULL) { + if (dname) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Renaming domains on migration not supported")); return -1; @@ -3890,7 +3888,7 @@ esxDomainMigratePerform(virDomainPtr domain, if (!(parsedUri = virURIParse(uri))) return -1; - if (parsedUri->scheme == NULL || STRCASENEQ(parsedUri->scheme, "vpxmigr")) { + if (!parsedUri->scheme || STRCASENEQ(parsedUri->scheme, "vpxmigr")) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Only vpxmigr:// migration URIs are supported")); goto cleanup; @@ -3906,7 +3904,7 @@ esxDomainMigratePerform(virDomainPtr domain, path_resourcePool = strtok_r(parsedUri->path, "/", &saveptr); path_hostSystem = strtok_r(NULL, "", &saveptr); - if (path_resourcePool == NULL || path_hostSystem == NULL) { + if (!path_resourcePool || !path_hostSystem) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Migration URI has to specify resource pool and host system")); goto cleanup; @@ -3936,12 +3934,12 @@ esxDomainMigratePerform(virDomainPtr domain, goto cleanup; } - if (eventList != NULL) { + if (eventList) { /* * FIXME: Need to report the complete list of events. Limit reporting * to the first event for now. */ - if (eventList->fullFormattedMessage != NULL) { + if (eventList->fullFormattedMessage) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not migrate domain, validation reported a " "problem: %s"), eventList->fullFormattedMessage); @@ -4028,7 +4026,7 @@ esxNodeGetFreeMemory(virConnectPtr conn) goto cleanup; } - for (dynamicProperty = resourcePool->propSet; dynamicProperty != NULL; + for (dynamicProperty = resourcePool->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "runtime.memory")) { if (esxVI_ResourcePoolResourceUsage_CastFromAnyType @@ -4042,7 +4040,7 @@ esxNodeGetFreeMemory(virConnectPtr conn) } } - if (resourcePoolResourceUsage == NULL) { + if (!resourcePoolResourceUsage) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve memory usage of resource pool")); goto cleanup; @@ -4225,7 +4223,7 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, def = virDomainSnapshotDefParseString(xmlDesc, priv->caps, priv->xmlopt, 0, 0); - if (def == NULL) { + if (!def) { return NULL; } @@ -4246,7 +4244,7 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, goto cleanup; } - if (snapshotTree != NULL) { + if (snapshotTree) { virReportError(VIR_ERR_OPERATION_INVALID, _("Snapshot '%s' already exists"), def->name); goto cleanup; @@ -4314,7 +4312,7 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, def.name = snapshot->name; def.description = snapshotTree->description; - def.parent = snapshotTreeParent != NULL ? snapshotTreeParent->name : NULL; + def.parent = snapshotTreeParent ? snapshotTreeParent->name : NULL; if (esxVI_DateTime_ConvertToCalendarTime(snapshotTree->createTime, &def.creationTime) < 0) { @@ -4392,7 +4390,7 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0; leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; - if (names == NULL || nameslen < 0) { + if (!names || nameslen < 0) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); return -1; } @@ -4485,7 +4483,7 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0; leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; - if (names == NULL || nameslen < 0) { + if (!names || nameslen < 0) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); return -1; } @@ -4574,7 +4572,7 @@ esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags) return -1; } - if (currentSnapshotTree != NULL) { + if (currentSnapshotTree) { esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree); return 1; } @@ -5025,7 +5023,7 @@ esxConnectListAllDomains(virConnectPtr conn, } needIdentity = MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT) || - domains != NULL; + domains; if (needIdentity) { /* Request required data for esxVI_GetVirtualMachineIdentity */ @@ -5039,7 +5037,7 @@ esxConnectListAllDomains(virConnectPtr conn, needPowerState = MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) || MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE) || - domains != NULL; + domains; if (needPowerState) { if (esxVI_String_AppendValueToList(&propertyNameList, @@ -5058,7 +5056,7 @@ esxConnectListAllDomains(virConnectPtr conn, ndoms = 1; } - for (virtualMachine = virtualMachineList; virtualMachine != NULL; + for (virtualMachine = virtualMachineList; virtualMachine; virtualMachine = virtualMachine->_next) { if (needIdentity) { VIR_FREE(name); @@ -5094,9 +5092,9 @@ esxConnectListAllDomains(virConnectPtr conn, } if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && - rootSnapshotTreeList != NULL) || + rootSnapshotTreeList) || (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && - rootSnapshotTreeList == NULL))) + !rootSnapshotTreeList))) continue; } @@ -5105,7 +5103,7 @@ esxConnectListAllDomains(virConnectPtr conn, autostart = false; if (autoStartDefaults->enabled == esxVI_Boolean_True) { - for (powerInfo = powerInfoList; powerInfo != NULL; + for (powerInfo = powerInfoList; powerInfo; powerInfo = powerInfo->_next) { if (STREQ(powerInfo->key->value, virtualMachine->obj->value)) { if (STRCASEEQ(powerInfo->startAction, "powerOn")) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 7bc8b60..052b969 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -51,7 +51,7 @@ int \ esxVI_##_type##_Alloc(esxVI_##_type **ptrptr) \ { \ - if (ptrptr == NULL || *ptrptr != NULL) { \ + if (!ptrptr || *ptrptr) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \ return -1; \ } \ @@ -69,7 +69,7 @@ { \ esxVI_##_type *item ATTRIBUTE_UNUSED; \ \ - if (ptrptr == NULL || *ptrptr == NULL) { \ + if (!ptrptr || !(*ptrptr)) { \ return; \ } \ \ @@ -95,7 +95,7 @@ ESX_VI__TEMPLATE__FREE(CURL, esxVI_SharedCURL *shared = item->shared; esxVI_MultiCURL *multi = item->multi; - if (shared != NULL) { + if (shared) { esxVI_SharedCURL_Remove(shared, item); if (shared->count == 0) { @@ -103,7 +103,7 @@ ESX_VI__TEMPLATE__FREE(CURL, } } - if (multi != NULL) { + if (multi) { esxVI_MultiCURL_Remove(multi, item); if (multi->count == 0) { @@ -111,11 +111,11 @@ ESX_VI__TEMPLATE__FREE(CURL, } } - if (item->handle != NULL) { + if (item->handle) { curl_easy_cleanup(item->handle); } - if (item->headers != NULL) { + if (item->headers) { curl_slist_free_all(item->headers); } @@ -129,7 +129,7 @@ esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *userdata) size_t available = 0; size_t requested = size * nmemb; - if (content == NULL) { + if (!content) { return 0; } @@ -155,7 +155,7 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *userdata) { virBufferPtr buffer = userdata; - if (buffer != NULL) { + if (buffer) { /* * Using a virBuffer to store the download data limits the downloadable * size. This is no problem as esxVI_CURL_Download and esxVI_CURL_Perform @@ -197,7 +197,7 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type, return 0; } - if (virStrncpy(buffer, info, size, size + 1) == NULL) { + if (!virStrncpy(buffer, info, size, size + 1)) { VIR_FREE(buffer); return 0; } @@ -304,14 +304,14 @@ esxVI_CURL_Perform(esxVI_CURL *curl, const char *url) int esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri *parsedUri) { - if (curl->handle != NULL) { + if (curl->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call")); return -1; } curl->handle = curl_easy_init(); - if (curl->handle == NULL) { + if (!curl->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize CURL")); return -1; @@ -330,7 +330,7 @@ esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri *parsedUri) */ curl->headers = curl_slist_append(curl->headers, "Expect:"); - if (curl->headers == NULL) { + if (!curl->headers) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not build CURL header list")); return -1; @@ -382,12 +382,12 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, virBuffer buffer = VIR_BUFFER_INITIALIZER; int responseCode = 0; - if (content == NULL || *content != NULL) { + if (!content || *content) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (length != NULL && *length > 0) { + if (length && *length > 0) { /* * Using a virBuffer to store the download data limits the downloadable * size. This is no problem as esxVI_CURL_Download is meant to download @@ -432,7 +432,7 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, goto cleanup; } - if (length != NULL) { + if (length) { *length = virBufferUse(&buffer); } @@ -441,7 +441,7 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, cleanup: VIR_FREE(range); - if (*content == NULL) { + if (!(*content)) { virBufferFreeAndReset(&buffer); return -1; } @@ -454,7 +454,7 @@ esxVI_CURL_Upload(esxVI_CURL *curl, const char *url, const char *content) { int responseCode = 0; - if (content == NULL) { + if (!content) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -559,7 +559,7 @@ ESX_VI__TEMPLATE__FREE(SharedCURL, return; } - if (item->handle != NULL) { + if (item->handle) { curl_share_cleanup(item->handle); } @@ -573,22 +573,22 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl) { size_t i; - if (curl->handle == NULL) { + if (!curl->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot share uninitialized CURL handle")); return -1; } - if (curl->shared != NULL) { + if (curl->shared) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot share CURL handle that is already shared")); return -1; } - if (shared->handle == NULL) { + if (!shared->handle) { shared->handle = curl_share_init(); - if (shared->handle == NULL) { + if (!shared->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize CURL (share)")); return -1; @@ -628,13 +628,13 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl) int esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esxVI_CURL *curl) { - if (curl->handle == NULL) { + if (!curl->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot unshare uninitialized CURL handle")); return -1; } - if (curl->shared == NULL) { + if (!curl->shared) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot unshare CURL handle that is not shared")); return -1; @@ -675,7 +675,7 @@ ESX_VI__TEMPLATE__FREE(MultiCURL, return; } - if (item->handle != NULL) { + if (item->handle) { curl_multi_cleanup(item->handle); } }) @@ -683,22 +683,22 @@ ESX_VI__TEMPLATE__FREE(MultiCURL, int esxVI_MultiCURL_Add(esxVI_MultiCURL *multi, esxVI_CURL *curl) { - if (curl->handle == NULL) { + if (!curl->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot add uninitialized CURL handle to a multi handle")); return -1; } - if (curl->multi != NULL) { + if (curl->multi) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot add CURL handle to a multi handle twice")); return -1; } - if (multi->handle == NULL) { + if (!multi->handle) { multi->handle = curl_multi_init(); - if (multi->handle == NULL) { + if (!multi->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize CURL (multi)")); return -1; @@ -720,14 +720,14 @@ esxVI_MultiCURL_Add(esxVI_MultiCURL *multi, esxVI_CURL *curl) int esxVI_MultiCURL_Remove(esxVI_MultiCURL *multi, esxVI_CURL *curl) { - if (curl->handle == NULL) { + if (!curl->handle) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot remove uninitialized CURL handle from a " "multi handle")); return -1; } - if (curl->multi == NULL) { + if (!curl->multi) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot remove CURL handle from a multi handle when it " "wasn't added before")); @@ -763,7 +763,7 @@ ESX_VI__TEMPLATE__ALLOC(Context) /* esxVI_Context_Free */ ESX_VI__TEMPLATE__FREE(Context, { - if (item->sessionLock != NULL) { + if (item->sessionLock) { virMutexDestroy(item->sessionLock); } @@ -795,9 +795,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, const char *ipAddress, const char *username, const char *password, esxUtil_ParsedUri *parsedUri) { - if (ctx == NULL || url == NULL || ipAddress == NULL || username == NULL || - password == NULL || ctx->url != NULL || ctx->service != NULL || - ctx->curl != NULL) { + if (!ctx || !url || !ipAddress || !username || + !password || ctx->url || ctx->service || ctx->curl) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -958,7 +957,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - if (ctx->computeResource->resourcePool == NULL) { + if (!ctx->computeResource->resourcePool) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve resource pool")); return -1; @@ -998,7 +997,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) /* Lookup Datacenter */ item = strtok_r(tmp, "/", &saveptr); - if (item == NULL) { + if (!item) { virReportError(VIR_ERR_INVALID_ARG, _("Path '%s' does not specify a datacenter"), path); goto cleanup; @@ -1006,7 +1005,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) root = ctx->service->rootFolder; - while (ctx->datacenter == NULL && item != NULL) { + while (!ctx->datacenter && item) { esxVI_Folder_Free(&folder); /* Try to lookup item as a folder */ @@ -1015,7 +1014,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (folder != NULL) { + if (folder) { /* It's a folder, use it as new lookup root */ if (root != ctx->service->rootFolder) { esxVI_ManagedObjectReference_Free(&root); @@ -1042,7 +1041,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) item = strtok_r(NULL, "/", &saveptr); } - if (ctx->datacenter == NULL) { + if (!ctx->datacenter) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find datacenter specified in '%s'"), path); goto cleanup; @@ -1056,7 +1055,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) ctx->datacenterPath = virBufferContentAndReset(&buffer); /* Lookup (Cluster)ComputeResource */ - if (item == NULL) { + if (!item) { virReportError(VIR_ERR_INVALID_ARG, _("Path '%s' does not specify a compute resource"), path); goto cleanup; @@ -1068,7 +1067,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) root = ctx->datacenter->hostFolder; - while (ctx->computeResource == NULL && item != NULL) { + while (!ctx->computeResource && item) { esxVI_Folder_Free(&folder); /* Try to lookup item as a folder */ @@ -1077,7 +1076,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (folder != NULL) { + if (folder) { /* It's a folder, use it as new lookup root */ if (root != ctx->datacenter->hostFolder) { esxVI_ManagedObjectReference_Free(&root); @@ -1105,14 +1104,14 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) item = strtok_r(NULL, "/", &saveptr); } - if (ctx->computeResource == NULL) { + if (!ctx->computeResource) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find compute resource specified in '%s'"), path); goto cleanup; } - if (ctx->computeResource->resourcePool == NULL) { + if (!ctx->computeResource->resourcePool) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve resource pool")); goto cleanup; @@ -1128,7 +1127,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) /* Lookup HostSystem */ if (STREQ(ctx->computeResource->_reference->type, "ClusterComputeResource")) { - if (item == NULL) { + if (!item) { virReportError(VIR_ERR_INVALID_ARG, _("Path '%s' does not specify a host system"), path); goto cleanup; @@ -1139,7 +1138,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) item = strtok_r(NULL, "/", &saveptr); } - if (item != NULL) { + if (item) { virReportError(VIR_ERR_INVALID_ARG, _("Path '%s' ends with an excess item"), path); goto cleanup; @@ -1155,7 +1154,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (ctx->hostSystem == NULL) { + if (!ctx->hostSystem) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find host system specified in '%s'"), path); goto cleanup; @@ -1169,7 +1168,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) } if (root != ctx->service->rootFolder && - (ctx->datacenter == NULL || root != ctx->datacenter->hostFolder)) { + (!ctx->datacenter || root != ctx->datacenter->hostFolder)) { esxVI_ManagedObjectReference_Free(&root); } @@ -1202,7 +1201,7 @@ esxVI_Context_LookupManagedObjectsByHostSystemIp(esxVI_Context *ctx, goto cleanup; } - if (ctx->computeResource->resourcePool == NULL) { + if (!ctx->computeResource->resourcePool) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve resource pool")); goto cleanup; @@ -1235,7 +1234,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, xmlXPathContextPtr xpathContext = NULL; xmlNodePtr responseNode = NULL; - if (request == NULL || response == NULL || *response != NULL) { + if (!request || !response || *response) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1273,7 +1272,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, _("(esx execute response)"), &xpathContext); - if ((*response)->document == NULL) { + if (!(*response)->document) { goto cleanup; } @@ -1286,7 +1285,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, virXPathNode("/soapenv:Envelope/soapenv:Body/soapenv:Fault", xpathContext); - if ((*response)->node == NULL) { + if (!(*response)->node) { virReportError(VIR_ERR_INTERNAL_ERROR, _("HTTP response code %d for call to '%s'. " "Fault is unknown, XPath evaluation failed"), @@ -1321,7 +1320,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, responseNode = virXPathNode(xpathExpression, xpathContext); - if (responseNode == NULL) { + if (!responseNode) { virReportError(VIR_ERR_INTERNAL_ERROR, _("XPath evaluation of response for call to '%s' " "failed"), methodName); @@ -1333,12 +1332,12 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, switch (occurrence) { case esxVI_Occurrence_RequiredItem: - if ((*response)->node == NULL) { + if (!(*response)->node) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Call to '%s' returned an empty result, " "expecting a non-empty result"), methodName); goto cleanup; - } else if ((*response)->node->next != NULL) { + } else if ((*response)->node->next) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Call to '%s' returned a list, expecting " "exactly one item"), methodName); @@ -1348,7 +1347,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, break; case esxVI_Occurrence_RequiredList: - if ((*response)->node == NULL) { + if (!(*response)->node) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Call to '%s' returned an empty result, " "expecting a non-empty result"), methodName); @@ -1358,8 +1357,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, break; case esxVI_Occurrence_OptionalItem: - if ((*response)->node != NULL && - (*response)->node->next != NULL) { + if ((*response)->node && + (*response)->node->next) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Call to '%s' returned a list, expecting " "exactly one item"), methodName); @@ -1373,7 +1372,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, break; case esxVI_Occurrence_None: - if ((*response)->node != NULL) { + if ((*response)->node) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Call to '%s' returned something, expecting " "an empty result"), methodName); @@ -1439,7 +1438,7 @@ esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration, { size_t i; - if (anyType == NULL || value == NULL) { + if (!anyType || !value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1454,7 +1453,7 @@ esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration, return -1; } - for (i = 0; enumeration->values[i].name != NULL; ++i) { + for (i = 0; enumeration->values[i].name; ++i) { if (STREQ(anyType->value, enumeration->values[i].name)) { *value = enumeration->values[i].value; return 0; @@ -1475,7 +1474,7 @@ esxVI_Enumeration_Serialize(const esxVI_Enumeration *enumeration, size_t i; const char *name = NULL; - if (element == NULL || output == NULL) { + if (!element || !output) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1484,14 +1483,14 @@ esxVI_Enumeration_Serialize(const esxVI_Enumeration *enumeration, return 0; } - for (i = 0; enumeration->values[i].name != NULL; ++i) { + for (i = 0; enumeration->values[i].name; ++i) { if (value == enumeration->values[i].value) { name = enumeration->values[i].name; break; } } - if (name == NULL) { + if (!name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1514,7 +1513,7 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration, int result = -1; char *name = NULL; - if (value == NULL) { + if (!value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1525,7 +1524,7 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration, return -1; } - for (i = 0; enumeration->values[i].name != NULL; ++i) { + for (i = 0; enumeration->values[i].name; ++i) { if (STREQ(name, enumeration->values[i].name)) { *value = enumeration->values[i].value; result = 0; @@ -1554,19 +1553,19 @@ esxVI_List_Append(esxVI_List **list, esxVI_List *item) { esxVI_List *next = NULL; - if (list == NULL || item == NULL) { + if (!list || !item) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (*list == NULL) { + if (!(*list)) { *list = item; return 0; } next = *list; - while (next->_next != NULL) { + while (next->_next) { next = next->_next; } @@ -1583,12 +1582,12 @@ esxVI_List_DeepCopy(esxVI_List **destList, esxVI_List *srcList, esxVI_List *dest = NULL; esxVI_List *src = NULL; - if (destList == NULL || *destList != NULL) { + if (!destList || *destList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (src = srcList; src != NULL; src = src->_next) { + for (src = srcList; src; src = src->_next) { if (deepCopyFunc(&dest, src) < 0 || esxVI_List_Append(destList, dest) < 0) { goto failure; @@ -1616,13 +1615,12 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list, esxVI_AnyType *childAnyType = NULL; esxVI_List *item = NULL; - if (list == NULL || *list != NULL || - castFromAnyTypeFunc == NULL || freeFunc == NULL) { + if (!list || *list || !castFromAnyTypeFunc || !freeFunc) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (anyType == NULL) { + if (!anyType) { return 0; } @@ -1633,7 +1631,7 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list, return -1; } - for (childNode = anyType->node->children; childNode != NULL; + for (childNode = anyType->node->children; childNode; childNode = childNode->next) { if (childNode->type != XML_ELEMENT_NODE) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1672,16 +1670,16 @@ esxVI_List_Serialize(esxVI_List *list, const char *element, { esxVI_List *item = NULL; - if (element == NULL || output == NULL || serializeFunc == NULL) { + if (!element || !output || !serializeFunc) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (list == NULL) { + if (!list) { return 0; } - for (item = list; item != NULL; item = item->_next) { + for (item = list; item; item = item->_next) { if (serializeFunc(item, element, output) < 0) { return -1; } @@ -1697,17 +1695,16 @@ esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list, { esxVI_List *item = NULL; - if (list == NULL || *list != NULL || - deserializeFunc == NULL || freeFunc == NULL) { + if (!list || *list || !deserializeFunc || !freeFunc) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (node == NULL) { + if (!node) { return 0; } - for (; node != NULL; node = node->next) { + for (; node; node = node->next) { if (node->type != XML_ELEMENT_NODE) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Wrong XML element type %d"), node->type); @@ -1750,7 +1747,7 @@ esxVI_BuildSelectSet(esxVI_SelectionSpec **selectSet, esxVI_SelectionSpec *selectionSpec = NULL; const char *currentSelectSetName = NULL; - if (selectSet == NULL) { + if (!selectSet) { /* * Don't check for *selectSet != NULL here because selectSet is a list * and might contain items already. This function appends to selectSet. @@ -1768,10 +1765,10 @@ esxVI_BuildSelectSet(esxVI_SelectionSpec **selectSet, traversalSpec->skip = esxVI_Boolean_False; - if (selectSetNames != NULL) { + if (selectSetNames) { currentSelectSetName = selectSetNames; - while (currentSelectSetName != NULL && *currentSelectSetName != '\0') { + while (currentSelectSetName && *currentSelectSetName != '\0') { if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0 || VIR_STRDUP(selectionSpec->name, currentSelectSetName) < 0 || esxVI_SelectionSpec_AppendToList(&traversalSpec->selectSet, @@ -1899,14 +1896,14 @@ esxVI_EnsureSession(esxVI_Context *ctx) esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_UserSession *currentSession = NULL; - if (ctx->sessionLock == NULL) { + if (!ctx->sessionLock) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no mutex")); return -1; } virMutexLock(ctx->sessionLock); - if (ctx->session == NULL) { + if (!ctx->session) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no session")); goto cleanup; } @@ -1943,7 +1940,7 @@ esxVI_EnsureSession(esxVI_Context *ctx) goto cleanup; } - for (dynamicProperty = sessionManager->propSet; dynamicProperty != NULL; + for (dynamicProperty = sessionManager->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "currentSession")) { if (esxVI_UserSession_CastFromAnyType(dynamicProperty->val, @@ -1957,7 +1954,7 @@ esxVI_EnsureSession(esxVI_Context *ctx) } } - if (currentSession == NULL) { + if (!currentSession) { esxVI_UserSession_Free(&ctx->session); if (esxVI_Login(ctx, ctx->username, ctx->password, NULL, @@ -2001,7 +1998,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, bool propertySpec_isAppended = false; esxVI_PropertyFilterSpec *propertyFilterSpec = NULL; - if (objectContentList == NULL || *objectContentList != NULL) { + if (!objectContentList || *objectContentList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -2094,7 +2091,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, goto cleanup; } - if (*objectContentList == NULL) { + if (!(*objectContentList)) { switch (occurrence) { case esxVI_Occurrence_OptionalItem: case esxVI_Occurrence_OptionalList: @@ -2133,7 +2130,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, objectSpec->obj = NULL; objectSpec->selectSet = NULL; - if (propertySpec != NULL) { + if (propertySpec) { propertySpec->type = NULL; propertySpec->pathSet = NULL; } @@ -2160,7 +2157,7 @@ esxVI_GetManagedEntityStatus(esxVI_ObjectContent *objectContent, { esxVI_DynamicProperty *dynamicProperty; - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, propertyName)) { return esxVI_ManagedEntityStatus_CastFromAnyType @@ -2183,7 +2180,7 @@ esxVI_GetVirtualMachinePowerState(esxVI_ObjectContent *virtualMachine, { esxVI_DynamicProperty *dynamicProperty; - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "runtime.powerState")) { return esxVI_VirtualMachinePowerState_CastFromAnyType @@ -2206,12 +2203,12 @@ esxVI_GetVirtualMachineQuestionInfo { esxVI_DynamicProperty *dynamicProperty; - if (questionInfo == NULL || *questionInfo != NULL) { + if (!questionInfo || *questionInfo) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "runtime.question")) { if (esxVI_VirtualMachineQuestionInfo_CastFromAnyType @@ -2232,12 +2229,12 @@ esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName, { esxVI_DynamicProperty *dynamicProperty; - if (value == NULL || *value != esxVI_Boolean_Undefined) { + if (!value || *value != esxVI_Boolean_Undefined) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, propertyName)) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -2268,12 +2265,12 @@ esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName, { esxVI_DynamicProperty *dynamicProperty; - if (value == NULL || *value != NULL) { + if (!value || *value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, propertyName)) { if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) { @@ -2284,7 +2281,7 @@ esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName, } } - if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) { + if (!(*value) && occurrence == esxVI_Occurrence_RequiredItem) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing '%s' property"), propertyName); return -1; @@ -2302,12 +2299,12 @@ esxVI_GetStringValue(esxVI_ObjectContent *objectContent, { esxVI_DynamicProperty *dynamicProperty; - if (value == NULL || *value != NULL) { + if (!value || *value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, propertyName)) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -2320,7 +2317,7 @@ esxVI_GetStringValue(esxVI_ObjectContent *objectContent, } } - if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) { + if (!(*value) && occurrence == esxVI_Occurrence_RequiredItem) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing '%s' property"), propertyName); return -1; @@ -2339,12 +2336,12 @@ esxVI_GetManagedObjectReference(esxVI_ObjectContent *objectContent, { esxVI_DynamicProperty *dynamicProperty; - if (value == NULL || *value != NULL) { + if (!value || *value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, propertyName)) { if (esxVI_ManagedObjectReference_CastFromAnyType @@ -2356,7 +2353,7 @@ esxVI_GetManagedObjectReference(esxVI_ObjectContent *objectContent, } } - if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) { + if (!(*value) && occurrence == esxVI_Occurrence_RequiredItem) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing '%s' property"), propertyName); return -1; @@ -2387,10 +2384,10 @@ esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx, goto cleanup; } - for (virtualMachine = virtualMachineList; virtualMachine != NULL; + for (virtualMachine = virtualMachineList; virtualMachine; virtualMachine = virtualMachine->_next) { for (dynamicProperty = virtualMachine->propSet; - dynamicProperty != NULL; + dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "runtime.powerState")) { if (esxVI_VirtualMachinePowerState_CastFromAnyType @@ -2433,7 +2430,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, return -1; } - if (id != NULL) { + if (id) { if (esxUtil_ParseVirtualMachineIDString (virtualMachine->obj->value, id) < 0 || *id <= 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2443,14 +2440,14 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, } } - if (name != NULL) { - if (*name != NULL) { + if (name) { + if (*name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); goto failure; } for (dynamicProperty = virtualMachine->propSet; - dynamicProperty != NULL; + dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "name")) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -2471,14 +2468,14 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, } } - if (*name == NULL) { + if (!(*name)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get name of virtual machine")); goto failure; } } - if (uuid != NULL) { + if (uuid) { if (esxVI_GetManagedEntityStatus(virtualMachine, "configStatus", &configStatus) < 0) { goto failure; @@ -2486,7 +2483,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, if (configStatus == esxVI_ManagedEntityStatus_Green) { for (dynamicProperty = virtualMachine->propSet; - dynamicProperty != NULL; + dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.uuid")) { if (esxVI_AnyType_ExpectType(dynamicProperty->val, @@ -2499,7 +2496,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, } } - if (uuid_string == NULL) { + if (!uuid_string) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get UUID of virtual machine")); goto failure; @@ -2522,7 +2519,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, return 0; failure: - if (name != NULL) { + if (name) { VIR_FREE(*name); } @@ -2539,7 +2536,7 @@ esxVI_GetNumberOfSnapshotTrees int count = 0; esxVI_VirtualMachineSnapshotTree *snapshotTree; - for (snapshotTree = snapshotTreeList; snapshotTree != NULL; + for (snapshotTree = snapshotTreeList; snapshotTree; snapshotTree = snapshotTree->_next) { if (!(leaves && snapshotTree->childSnapshotList)) count++; @@ -2564,7 +2561,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, esxVI_VirtualMachineSnapshotTree *snapshotTree; for (snapshotTree = snapshotTreeList; - snapshotTree != NULL && count < nameslen; + snapshotTree && count < nameslen; snapshotTree = snapshotTree->_next) { if (!(leaves && snapshotTree->childSnapshotList)) { if (VIR_STRDUP(names[count], snapshotTree->name) < 0) @@ -2612,13 +2609,13 @@ esxVI_GetSnapshotTreeByName { esxVI_VirtualMachineSnapshotTree *candidate; - if (snapshotTree == NULL || *snapshotTree != NULL || - (snapshotTreeParent && *snapshotTreeParent != NULL)) { + if (!snapshotTree || *snapshotTree || + (snapshotTreeParent && *snapshotTreeParent)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (candidate = snapshotTreeList; candidate != NULL; + for (candidate = snapshotTreeList; candidate; candidate = candidate->_next) { if (STREQ(candidate->name, name)) { *snapshotTree = candidate; @@ -2630,7 +2627,7 @@ esxVI_GetSnapshotTreeByName if (esxVI_GetSnapshotTreeByName(candidate->childSnapshotList, name, snapshotTree, snapshotTreeParent, occurrence) > 0) { - if (snapshotTreeParent && *snapshotTreeParent == NULL) { + if (snapshotTreeParent && !(*snapshotTreeParent)) { *snapshotTreeParent = candidate; } @@ -2658,12 +2655,12 @@ esxVI_GetSnapshotTreeBySnapshot { esxVI_VirtualMachineSnapshotTree *candidate; - if (snapshotTree == NULL || *snapshotTree != NULL) { + if (!snapshotTree || *snapshotTree) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - for (candidate = snapshotTreeList; candidate != NULL; + for (candidate = snapshotTreeList; candidate; candidate = candidate->_next) { if (STREQ(candidate->snapshot->value, snapshot->value)) { *snapshotTree = candidate; @@ -2723,7 +2720,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid, esxVI_ManagedObjectReference *managedObjectReference = NULL; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; - if (virtualMachine == NULL || *virtualMachine != NULL) { + if (!virtualMachine || *virtualMachine) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -2736,7 +2733,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid, return -1; } - if (managedObjectReference == NULL) { + if (!managedObjectReference) { if (occurrence == esxVI_Occurrence_OptionalItem) { result = 0; @@ -2778,7 +2775,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, esxVI_ObjectContent *candidate = NULL; char *name_candidate = NULL; - if (virtualMachine == NULL || *virtualMachine != NULL) { + if (!virtualMachine || *virtualMachine) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -2791,7 +2788,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, goto cleanup; } - for (candidate = virtualMachineList; candidate != NULL; + for (candidate = virtualMachineList; candidate; candidate = candidate->_next) { VIR_FREE(name_candidate); @@ -2811,7 +2808,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, break; } - if (*virtualMachine == NULL) { + if (!(*virtualMachine)) { if (occurrence == esxVI_Occurrence_OptionalItem) { result = 0; @@ -2862,14 +2859,14 @@ esxVI_LookupVirtualMachineByUuidAndPrepareForTask goto cleanup; } - if (questionInfo != NULL && + if (questionInfo && esxVI_HandleVirtualMachineQuestion(ctx, (*virtualMachine)->obj, questionInfo, autoAnswer, &blocked) < 0) { goto cleanup; } - if (pendingTaskInfoList != NULL) { + if (pendingTaskInfoList) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Other tasks are pending for this domain")); goto cleanup; @@ -2913,7 +2910,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, esxVI_ObjectContent *candidate = NULL; char *name_candidate; - if (datastore == NULL || *datastore != NULL) { + if (!datastore || *datastore) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -2929,7 +2926,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, } /* Search for a matching datastore */ - for (candidate = datastoreList; candidate != NULL; + for (candidate = datastoreList; candidate; candidate = candidate->_next) { name_candidate = NULL; @@ -2950,7 +2947,7 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, } } - if (*datastore == NULL && occurrence != esxVI_Occurrence_OptionalItem) { + if (!(*datastore) && occurrence != esxVI_Occurrence_OptionalItem) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find datastore with name '%s'"), name); goto cleanup; @@ -2981,7 +2978,7 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, esxVI_DatastoreHostMount *datastoreHostMountList = NULL; esxVI_DatastoreHostMount *datastoreHostMount = NULL; - if (datastore == NULL || *datastore != NULL) { + if (!datastore || *datastore) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -2996,11 +2993,11 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, } /* Search for a matching datastore */ - for (candidate = datastoreList; candidate != NULL; + for (candidate = datastoreList; candidate; candidate = candidate->_next) { esxVI_DatastoreHostMount_Free(&datastoreHostMountList); - for (dynamicProperty = candidate->propSet; dynamicProperty != NULL; + for (dynamicProperty = candidate->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "host")) { if (esxVI_DatastoreHostMount_CastListFromAnyType @@ -3012,12 +3009,12 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, } } - if (datastoreHostMountList == NULL) { + if (!datastoreHostMountList) { continue; } for (datastoreHostMount = datastoreHostMountList; - datastoreHostMount != NULL; + datastoreHostMount; datastoreHostMount = datastoreHostMount->_next) { if (STRNEQ(ctx->hostSystem->_reference->value, datastoreHostMount->key->value)) { @@ -3037,7 +3034,7 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, } } - if (*datastore == NULL && occurrence != esxVI_Occurrence_OptionalItem) { + if (!(*datastore) && occurrence != esxVI_Occurrence_OptionalItem) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find datastore containing absolute path '%s'"), absolutePath); @@ -3069,7 +3066,7 @@ esxVI_LookupDatastoreHostMount(esxVI_Context *ctx, esxVI_DatastoreHostMount *hostMountList = NULL; esxVI_DatastoreHostMount *candidate = NULL; - if (hostMount == NULL || *hostMount != NULL) { + if (!hostMount || *hostMount) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3081,7 +3078,7 @@ esxVI_LookupDatastoreHostMount(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "host")) { if (esxVI_DatastoreHostMount_CastListFromAnyType @@ -3095,7 +3092,7 @@ esxVI_LookupDatastoreHostMount(esxVI_Context *ctx, } } - for (candidate = hostMountList; candidate != NULL; + for (candidate = hostMountList; candidate; candidate = candidate->_next) { if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value)) { continue; @@ -3108,7 +3105,7 @@ esxVI_LookupDatastoreHostMount(esxVI_Context *ctx, break; } - if (*hostMount == NULL && occurrence == esxVI_Occurrence_RequiredItem) { + if (!(*hostMount) && occurrence == esxVI_Occurrence_RequiredItem) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup datastore host mount")); goto cleanup; @@ -3135,7 +3132,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, esxVI_ObjectContent *objectContent = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (taskInfo == NULL || *taskInfo != NULL) { + if (!taskInfo || *taskInfo) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3147,7 +3144,7 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL; + for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "info")) { if (esxVI_TaskInfo_CastFromAnyType(dynamicProperty->val, @@ -3184,13 +3181,13 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_TaskInfo *taskInfo = NULL; - if (pendingTaskInfoList == NULL || *pendingTaskInfoList != NULL) { + if (!pendingTaskInfoList || *pendingTaskInfoList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } /* Get list of recent tasks */ - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "recentTask")) { if (esxVI_ManagedObjectReference_CastListFromAnyType @@ -3203,7 +3200,7 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine } /* Lookup task info for each task */ - for (recentTask = recentTaskList; recentTask != NULL; + for (recentTask = recentTaskList; recentTask; recentTask = recentTask->_next) { if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) { goto cleanup; @@ -3256,13 +3253,13 @@ esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx, goto cleanup; } - if (virtualMachine != NULL) { + if (virtualMachine) { if (esxVI_GetVirtualMachineQuestionInfo(virtualMachine, &questionInfo) < 0) { goto cleanup; } - if (questionInfo != NULL && + if (questionInfo && esxVI_HandleVirtualMachineQuestion(ctx, virtualMachine->obj, questionInfo, autoAnswer, blocked) < 0) { @@ -3292,7 +3289,7 @@ esxVI_LookupRootSnapshotTreeList esxVI_ObjectContent *virtualMachine = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (rootSnapshotTreeList == NULL || *rootSnapshotTreeList != NULL) { + if (!rootSnapshotTreeList || *rootSnapshotTreeList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3305,7 +3302,7 @@ esxVI_LookupRootSnapshotTreeList goto cleanup; } - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) { if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType @@ -3348,7 +3345,7 @@ esxVI_LookupCurrentSnapshotTree esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL; esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL; - if (currentSnapshotTree == NULL || *currentSnapshotTree != NULL) { + if (!currentSnapshotTree || *currentSnapshotTree) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3362,7 +3359,7 @@ esxVI_LookupCurrentSnapshotTree goto cleanup; } - for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL; + for (dynamicProperty = virtualMachine->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "snapshot.currentSnapshot")) { if (esxVI_ManagedObjectReference_CastFromAnyType @@ -3379,7 +3376,7 @@ esxVI_LookupCurrentSnapshotTree } } - if (currentSnapshot == NULL) { + if (!currentSnapshot) { if (occurrence == esxVI_Occurrence_OptionalItem) { result = 0; @@ -3391,7 +3388,7 @@ esxVI_LookupCurrentSnapshotTree } } - if (rootSnapshotTreeList == NULL) { + if (!rootSnapshotTreeList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup root snapshot list")); goto cleanup; @@ -3445,7 +3442,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, esxVI_TaskInfo *taskInfo = NULL; esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL; - if (fileInfo == NULL || *fileInfo != NULL) { + if (!fileInfo || *fileInfo) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3579,7 +3576,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, } /* Interpret search result */ - if (searchResults->file == NULL) { + if (!searchResults->file) { if (occurrence == esxVI_Occurrence_OptionalItem) { result = 0; @@ -3599,7 +3596,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, cleanup: /* Don't double free fileName */ - if (searchSpec != NULL && searchSpec->matchPattern != NULL) { + if (searchSpec && searchSpec->matchPattern) { searchSpec->matchPattern->value = NULL; } @@ -3645,7 +3642,7 @@ esxVI_LookupDatastoreContentByDatastoreName char *taskInfoErrorMessage = NULL; esxVI_TaskInfo *taskInfo = NULL; - if (searchResultsList == NULL || *searchResultsList != NULL) { + if (!searchResultsList || *searchResultsList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3757,7 +3754,7 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx, esxVI_FileInfo *fileInfo = NULL; char *uuid_string = NULL; - if (key == NULL || *key != NULL) { + if (!key || *key) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3769,7 +3766,7 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx, goto cleanup; } - if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) != NULL) { + if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo)) { /* VirtualDisks have a UUID, use it as key */ if (esxVI_QueryVirtualDiskUuid(ctx, datastorePath, ctx->datacenter->_reference, @@ -3786,7 +3783,7 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx, } } - if (*key == NULL) { + if (!(*key)) { /* Other files don't have a UUID, fall back to the path as key */ if (VIR_STRDUP(*key, datastorePath) < 0) { goto cleanup; @@ -3813,7 +3810,7 @@ esxVI_LookupAutoStartDefaults(esxVI_Context *ctx, esxVI_ObjectContent *hostAutoStartManager = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (defaults == NULL || *defaults != NULL) { + if (!defaults || *defaults) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3833,7 +3830,7 @@ esxVI_LookupAutoStartDefaults(esxVI_Context *ctx, } for (dynamicProperty = hostAutoStartManager->propSet; - dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) { + dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.defaults")) { if (esxVI_AutoStartDefaults_CastFromAnyType(dynamicProperty->val, defaults) < 0) { @@ -3844,7 +3841,7 @@ esxVI_LookupAutoStartDefaults(esxVI_Context *ctx, } } - if (*defaults == NULL) { + if (!(*defaults)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve the AutoStartDefaults object")); goto cleanup; @@ -3870,7 +3867,7 @@ esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx, esxVI_ObjectContent *hostAutoStartManager = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (powerInfoList == NULL || *powerInfoList != NULL) { + if (!powerInfoList || *powerInfoList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3890,7 +3887,7 @@ esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx, } for (dynamicProperty = hostAutoStartManager->propSet; - dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) { + dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.powerInfo")) { if (esxVI_AutoStartPowerInfo_CastListFromAnyType (dynamicProperty->val, powerInfoList) < 0) { @@ -3921,7 +3918,7 @@ esxVI_LookupPhysicalNicList(esxVI_Context *ctx, esxVI_ObjectContent *hostSystem = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (physicalNicList == NULL || *physicalNicList != NULL) { + if (!physicalNicList || *physicalNicList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3933,7 +3930,7 @@ esxVI_LookupPhysicalNicList(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.network.pnic")) { if (esxVI_PhysicalNic_CastListFromAnyType(dynamicProperty->val, @@ -3965,7 +3962,7 @@ esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name, esxVI_PhysicalNic *physicalNicList = NULL; esxVI_PhysicalNic *candidate = NULL; - if (physicalNic == NULL || *physicalNic != NULL) { + if (!physicalNic || *physicalNic) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -3975,7 +3972,7 @@ esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name, } /* Search for a matching physical NIC */ - for (candidate = physicalNicList; candidate != NULL; + for (candidate = physicalNicList; candidate; candidate = candidate->_next) { if (STRCASEEQ(candidate->device, name)) { if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) { @@ -3989,7 +3986,7 @@ esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name, } } - if (*physicalNic == NULL && occurrence != esxVI_Occurrence_OptionalItem) { + if (!(*physicalNic) && occurrence != esxVI_Occurrence_OptionalItem) { virReportError(VIR_ERR_NO_INTERFACE, _("Could not find physical NIC with name '%s'"), name); goto cleanup; @@ -4014,7 +4011,7 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac, esxVI_PhysicalNic *physicalNicList = NULL; esxVI_PhysicalNic *candidate = NULL; - if (physicalNic == NULL || *physicalNic != NULL) { + if (!physicalNic || *physicalNic) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4024,7 +4021,7 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac, } /* Search for a matching physical NIC */ - for (candidate = physicalNicList; candidate != NULL; + for (candidate = physicalNicList; candidate; candidate = candidate->_next) { if (STRCASEEQ(candidate->mac, mac)) { if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) { @@ -4038,7 +4035,7 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac, } } - if (*physicalNic == NULL && occurrence != esxVI_Occurrence_OptionalItem) { + if (!(*physicalNic) && occurrence != esxVI_Occurrence_OptionalItem) { virReportError(VIR_ERR_NO_INTERFACE, _("Could not find physical NIC with MAC address '%s'"), mac); goto cleanup; @@ -4063,7 +4060,7 @@ esxVI_LookupHostVirtualSwitchList(esxVI_Context *ctx, esxVI_ObjectContent *hostSystem = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (hostVirtualSwitchList == NULL || *hostVirtualSwitchList != NULL) { + if (!hostVirtualSwitchList || *hostVirtualSwitchList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4075,7 +4072,7 @@ esxVI_LookupHostVirtualSwitchList(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.network.vswitch")) { if (esxVI_HostVirtualSwitch_CastListFromAnyType @@ -4107,7 +4104,7 @@ esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name, esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL; esxVI_HostVirtualSwitch *candidate = NULL; - if (hostVirtualSwitch == NULL || *hostVirtualSwitch != NULL) { + if (!hostVirtualSwitch || *hostVirtualSwitch) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4117,7 +4114,7 @@ esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name, } /* Search for a matching HostVirtualSwitch */ - for (candidate = hostVirtualSwitchList; candidate != NULL; + for (candidate = hostVirtualSwitchList; candidate; candidate = candidate->_next) { if (STREQ(candidate->name, name)) { if (esxVI_HostVirtualSwitch_DeepCopy(hostVirtualSwitch, @@ -4132,7 +4129,7 @@ esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name, } } - if (*hostVirtualSwitch == NULL && + if (!(*hostVirtualSwitch) && occurrence != esxVI_Occurrence_OptionalItem) { virReportError(VIR_ERR_NO_NETWORK, _("Could not find HostVirtualSwitch with name '%s'"), @@ -4159,7 +4156,7 @@ esxVI_LookupHostPortGroupList(esxVI_Context *ctx, esxVI_ObjectContent *hostSystem = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; - if (hostPortGroupList == NULL || *hostPortGroupList != NULL) { + if (!hostPortGroupList || *hostPortGroupList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4171,7 +4168,7 @@ esxVI_LookupHostPortGroupList(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.network.portgroup")) { if (esxVI_HostPortGroup_CastListFromAnyType @@ -4221,25 +4218,25 @@ esxVI_HandleVirtualMachineQuestion int answerIndex = 0; char *possibleAnswers = NULL; - if (blocked == NULL) { + if (!blocked) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } *blocked = false; - if (questionInfo->choice->choiceInfo != NULL) { + if (questionInfo->choice->choiceInfo) { for (elementDescription = questionInfo->choice->choiceInfo; - elementDescription != NULL; + elementDescription; elementDescription = elementDescription->_next) { virBufferAsprintf(&buffer, "'%s'", elementDescription->label); - if (elementDescription->_next != NULL) { + if (elementDescription->_next) { virBufferAddLit(&buffer, ", "); } - if (answerChoice == NULL && - questionInfo->choice->defaultIndex != NULL && + if (!answerChoice && + questionInfo->choice->defaultIndex && questionInfo->choice->defaultIndex->value == answerIndex) { answerChoice = elementDescription; } @@ -4256,7 +4253,7 @@ esxVI_HandleVirtualMachineQuestion } if (autoAnswer) { - if (possibleAnswers == NULL) { + if (!possibleAnswers) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Pending question blocks virtual machine execution, " "question is '%s', no possible answers"), @@ -4264,7 +4261,7 @@ esxVI_HandleVirtualMachineQuestion *blocked = true; goto cleanup; - } else if (answerChoice == NULL) { + } else if (!answerChoice) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Pending question blocks virtual machine execution, " "question is '%s', possible answers are %s, but no " @@ -4285,7 +4282,7 @@ esxVI_HandleVirtualMachineQuestion goto cleanup; } } else { - if (possibleAnswers != NULL) { + if (possibleAnswers) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Pending question blocks virtual machine execution, " "question is '%s', possible answers are %s"), @@ -4340,7 +4337,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, bool blocked; esxVI_TaskInfo *taskInfo = NULL; - if (errorMessage == NULL || *errorMessage != NULL) { + if (!errorMessage || *errorMessage) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4387,7 +4384,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, state != esxVI_TaskInfoState_Error) { esxVI_UpdateSet_Free(&updateSet); - if (virtualMachineUuid != NULL) { + if (virtualMachineUuid) { if (esxVI_LookupAndHandleVirtualMachineQuestion (ctx, virtualMachineUuid, virtualMachineOccurrence, autoAnswer, &blocked) < 0) { @@ -4425,17 +4422,17 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, if (VIR_STRDUP(version, updateSet->version) < 0) goto cleanup; - if (updateSet->filterSet == NULL) { + if (!updateSet->filterSet) { continue; } for (propertyFilterUpdate = updateSet->filterSet; - propertyFilterUpdate != NULL; + propertyFilterUpdate; propertyFilterUpdate = propertyFilterUpdate->_next) { for (objectUpdate = propertyFilterUpdate->objectSet; - objectUpdate != NULL; objectUpdate = objectUpdate->_next) { + objectUpdate; objectUpdate = objectUpdate->_next) { for (propertyChange = objectUpdate->changeSet; - propertyChange != NULL; + propertyChange; propertyChange = propertyChange->_next) { if (STREQ(propertyChange->name, "info.state")) { if (propertyChange->op == esxVI_PropertyChangeOp_Add || @@ -4449,7 +4446,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } } - if (propertyValue == NULL) { + if (!propertyValue) { continue; } @@ -4471,10 +4468,10 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, goto cleanup; } - if (taskInfo->error == NULL) { + if (!taskInfo->error) { if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0) goto cleanup; - } else if (taskInfo->error->localizedMessage == NULL) { + } else if (!taskInfo->error->localizedMessage) { if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0) goto cleanup; } else { @@ -4492,11 +4489,11 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, * Remove values given by the caller from the data structures to prevent * them from being freed by the call to esxVI_PropertyFilterSpec_Free(). */ - if (objectSpec != NULL) { + if (objectSpec) { objectSpec->obj = NULL; } - if (propertySpec != NULL) { + if (propertySpec) { propertySpec->type = NULL; } @@ -4627,19 +4624,19 @@ esxVI_LookupHostInternetScsiHbaStaticTargetByName goto cleanup; } - if (hostInternetScsiHba == NULL) { + if (!hostInternetScsiHba) { /* iSCSI adapter may not be enabled for this host */ return 0; } for (candidate = hostInternetScsiHba->configuredStaticTarget; - candidate != NULL; candidate = candidate->_next) { + candidate; candidate = candidate->_next) { if (STREQ(candidate->iScsiName, name)) { break; } } - if (candidate == NULL) { + if (!candidate) { if (occurrence == esxVI_Occurrence_RequiredItem) { virReportError(VIR_ERR_NO_STORAGE_POOL, _("Could not find storage pool with name: %s"), name); @@ -4680,13 +4677,13 @@ esxVI_LookupHostInternetScsiHba(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.storageDevice.hostBusAdapter")) { if (esxVI_HostHostBusAdapter_CastListFromAnyType - (dynamicProperty->val, &hostHostBusAdapterList) < 0 || - hostHostBusAdapterList == NULL) { + (dynamicProperty->val, &hostHostBusAdapterList) < 0 || + !hostHostBusAdapterList) { goto cleanup; } } else { @@ -4696,7 +4693,7 @@ esxVI_LookupHostInternetScsiHba(esxVI_Context *ctx, /* See vSphere API documentation about HostInternetScsiHba for details */ for (hostHostBusAdapter = hostHostBusAdapterList; - hostHostBusAdapter != NULL; + hostHostBusAdapter; hostHostBusAdapter = hostHostBusAdapter->_next) { esxVI_HostInternetScsiHba *candidate= esxVI_HostInternetScsiHba_DynamicCast(hostHostBusAdapter); @@ -4737,7 +4734,7 @@ esxVI_LookupScsiLunList(esxVI_Context *ctx, esxVI_ScsiLun **scsiLunList) goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.storageDevice.scsiLun")) { if (esxVI_ScsiLun_CastListFromAnyType(dynamicProperty->val, @@ -4777,7 +4774,7 @@ esxVI_LookupHostScsiTopologyLunListByTargetName bool found = false; esxVI_HostInternetScsiTargetTransport *candidate = NULL; - if (hostScsiTopologyLunList == NULL || *hostScsiTopologyLunList != NULL) { + if (!hostScsiTopologyLunList || *hostScsiTopologyLunList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4790,7 +4787,7 @@ esxVI_LookupHostScsiTopologyLunListByTargetName goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.storageDevice.scsiTopology.adapter")) { @@ -4814,26 +4811,26 @@ esxVI_LookupHostScsiTopologyLunListByTargetName /* See vSphere API documentation about HostScsiTopologyInterface */ for (hostScsiInterface = hostScsiInterfaceList; - hostScsiInterface != NULL && !found; + hostScsiInterface && !found; hostScsiInterface = hostScsiInterface->_next) { for (hostScsiTopologyTarget = hostScsiInterface->target; - hostScsiTopologyTarget != NULL; + hostScsiTopologyTarget; hostScsiTopologyTarget = hostScsiTopologyTarget->_next) { candidate = esxVI_HostInternetScsiTargetTransport_DynamicCast (hostScsiTopologyTarget->transport); - if (candidate != NULL && STREQ(candidate->iScsiName, name)) { + if (candidate && STREQ(candidate->iScsiName, name)) { found = true; break; } } } - if (!found || hostScsiTopologyTarget == NULL) { + if (!found || !hostScsiTopologyTarget) { goto cleanup; } - if (hostScsiTopologyTarget->lun == NULL) { + if (!hostScsiTopologyTarget->lun) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Target not found")); goto cleanup; @@ -4872,7 +4869,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, esxVI_HostScsiTopologyLun *hostScsiTopologyLun; bool found = false; - if (poolName == NULL || *poolName != NULL) { + if (!poolName || *poolName) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -4885,7 +4882,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, goto cleanup; } - for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL; + for (dynamicProperty = hostSystem->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, "config.storageDevice.scsiTopology.adapter")) { @@ -4902,25 +4899,25 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, } } - if (hostScsiInterfaceList == NULL) { + if (!hostScsiInterfaceList) { /* iSCSI adapter may not be enabled */ return 0; } /* See vSphere API documentation about HostScsiTopologyInterface */ for (hostScsiInterface = hostScsiInterfaceList; - hostScsiInterface != NULL && !found; + hostScsiInterface && !found; hostScsiInterface = hostScsiInterface->_next) { for (hostScsiTopologyTarget = hostScsiInterface->target; - hostScsiTopologyTarget != NULL; + hostScsiTopologyTarget; hostScsiTopologyTarget = hostScsiTopologyTarget->_next) { candidate = esxVI_HostInternetScsiTargetTransport_DynamicCast (hostScsiTopologyTarget->transport); - if (candidate != NULL) { + if (candidate) { /* iterate hostScsiTopologyLun list to find matching key */ for (hostScsiTopologyLun = hostScsiTopologyTarget->lun; - hostScsiTopologyLun != NULL; + hostScsiTopologyLun; hostScsiTopologyLun = hostScsiTopologyLun->_next) { if (STREQ(hostScsiTopologyLun->scsiLun, key) && VIR_STRDUP(*poolName, candidate->iScsiName) < 0) @@ -5003,7 +5000,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, esxVI_ObjectContent *objectContentList = NULL; \ esxVI_DynamicProperty *dynamicProperty = NULL; \ \ - if (ptrptr == NULL || *ptrptr != NULL) { \ + if (!ptrptr || *ptrptr) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ @@ -5011,7 +5008,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, \ propertyNameList = selectedPropertyNameList; \ \ - if (propertyNameList == NULL && \ + if (!propertyNameList && \ esxVI_String_AppendValueListToList \ (&propertyNameList, completePropertyNameValueList) < 0) { \ goto cleanup; \ @@ -5024,7 +5021,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, goto cleanup; \ } \ \ - if (objectContent == NULL) { \ + if (!objectContent) { \ /* not found, exit early */ \ result = 0; \ goto cleanup; \ @@ -5040,7 +5037,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, } \ \ for (dynamicProperty = objectContent->propSet; \ - dynamicProperty != NULL; \ + dynamicProperty; \ dynamicProperty = dynamicProperty->_next) { \ _cast_from_anytype \ \ @@ -5083,8 +5080,8 @@ esxVI_LookupManagedObjectHelper(esxVI_Context *ctx, esxVI_ObjectContent *candidate = NULL; char *name_candidate; - if (objectContent == NULL || *objectContent != NULL || - objectContentList == NULL || *objectContentList != NULL) { + if (!objectContent || *objectContent || + !objectContentList || *objectContentList) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -5102,8 +5099,8 @@ esxVI_LookupManagedObjectHelper(esxVI_Context *ctx, } /* Search for a matching item */ - if (name != NULL) { - for (candidate = *objectContentList; candidate != NULL; + if (name) { + for (candidate = *objectContentList; candidate; candidate = candidate->_next) { name_candidate = NULL; @@ -5121,9 +5118,9 @@ esxVI_LookupManagedObjectHelper(esxVI_Context *ctx, candidate = *objectContentList; } - if (candidate == NULL) { + if (!candidate) { if (occurrence != esxVI_Occurrence_OptionalItem) { - if (name != NULL) { + if (name) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find %s with name '%s'"), type, name); } else { diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c index 2279e62..519daf6 100644 --- a/src/esx/esx_vi_methods.c +++ b/src/esx/esx_vi_methods.c @@ -40,7 +40,7 @@ #define ESX_VI__METHOD__CHECK_OUTPUT__NotNone \ - if (output == NULL || *output != 0) { \ + if (!output || *output) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \ return -1; \ } @@ -87,7 +87,7 @@ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type, _suffix) \ - if (response->node != NULL && \ + if (response->node && \ esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \ goto cleanup; \ } @@ -95,7 +95,7 @@ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type, _suffix) \ - if (response->node != NULL && \ + if (response->node && \ esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ goto cleanup; \ } @@ -161,7 +161,7 @@ #define ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(_type, _name) \ esxVI_##_type *_this = NULL; \ \ - if (ctx->service == NULL) { \ + if (!ctx->service) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call")); \ return -1; \ } \ @@ -236,7 +236,7 @@ esxVI_RetrieveServiceContent(esxVI_Context *ctx, ESX_VI__SOAP__REQUEST_FOOTER; esxVI_Response *response = NULL; - if (serviceContent == NULL || *serviceContent != NULL) { + if (!serviceContent || *serviceContent) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 03df444..2d6f8db 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -43,7 +43,7 @@ int \ esxVI_##__type##_Alloc(esxVI_##__type **ptrptr) \ { \ - if (ptrptr == NULL || *ptrptr != NULL) { \ + if (!ptrptr || *ptrptr) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \ return -1; \ } \ @@ -64,7 +64,7 @@ { \ esxVI_##_type *item ATTRIBUTE_UNUSED; \ \ - if (ptrptr == NULL || *ptrptr == NULL) { \ + if (!ptrptr || !(*ptrptr)) { \ return; \ } \ \ @@ -101,13 +101,13 @@ int \ esxVI_##_type##_DeepCopy(esxVI_##_type **dest, esxVI_##_type *src) \ { \ - if (dest == NULL || *dest != NULL) { \ + if (!dest || *dest) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ } \ \ - if (src == NULL) { \ + if (!src) { \ return 0; \ } \ \ @@ -195,7 +195,7 @@ { \ _dest_type *item ATTRIBUTE_UNUSED; \ \ - if (anyType == NULL || ptrptr == NULL || *ptrptr != NULL) { \ + if (!anyType || !ptrptr || *ptrptr) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ @@ -246,13 +246,13 @@ esxVI_##_type##_Serialize(esxVI_##_type *item, \ const char *element, virBufferPtr output) \ { \ - if (element == NULL || output == NULL) { \ + if (!element || !output) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ } \ \ - if (item == NULL) { \ + if (!item) { \ return 0; \ } \ \ @@ -288,7 +288,7 @@ \ _extra1 \ \ - if (ptrptr == NULL || *ptrptr != NULL) { \ + if (!ptrptr || *ptrptr) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ @@ -300,7 +300,7 @@ \ _extra2 \ \ - for (childNode = node->children; childNode != NULL; \ + for (childNode = node->children; childNode; \ childNode = childNode->next) { \ if (childNode->type != XML_ELEMENT_NODE) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ @@ -342,7 +342,7 @@ char *string; \ long long value; \ \ - if (number == NULL || *number != NULL) { \ + if (!number || *number) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ @@ -354,7 +354,7 @@ \ string = (char *)xmlNodeListGetString(node->doc, node->children, 1); \ \ - if (string == NULL) { \ + if (!string) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ _("XML node doesn't contain text, expecting an %s "\ "value"), _xsdType); \ @@ -614,7 +614,7 @@ esxVI_##__type * \ esxVI_##__type##_DynamicCast(void *item) \ { \ - if (item == NULL) { \ + if (!item) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return NULL; \ @@ -633,13 +633,13 @@ int \ esxVI_##__type##_DeepCopy(esxVI_##__type **dest, esxVI_##__type *src) \ { \ - if (dest == NULL || *dest != NULL) { \ + if (!dest || *dest) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Invalid argument")); \ return -1; \ } \ \ - if (src == NULL) { \ + if (!src) { \ return 0; \ } \ \ @@ -714,7 +714,7 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType, int result = -1; char *type = NULL; - if (actualType == NULL || *actualType != esxVI_Type_Undefined) { + if (!actualType || *actualType != esxVI_Type_Undefined) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -723,7 +723,7 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType, (node, BAD_CAST "type", BAD_CAST "http://www.w3.org/2001/XMLSchema-instance"); - if (type == NULL) { + if (!type) { /* no actual type specified, use base type instead */ *actualType = baseType; return 0; @@ -844,7 +844,7 @@ esxVI_Type_ToString(esxVI_Type type) esxVI_Type esxVI_Type_FromString(const char *type) { - if (type == NULL || STREQ(type, "<undefined>")) { + if (!type || STREQ(type, "<undefined>")) { return esxVI_Type_Undefined; } else if (STREQ(type, "xsd:boolean")) { return esxVI_Type_Boolean; @@ -942,12 +942,12 @@ esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type) int esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src) { - if (dest == NULL || *dest != NULL) { + if (!dest || *dest) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (src == NULL) { + if (!src) { return 0; } @@ -958,7 +958,7 @@ esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src) (*dest)->_type = src->_type; (*dest)->node = xmlCopyNode(src->node, 1); - if ((*dest)->node == NULL) { + if (!(*dest)->node) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not copy an XML node")); goto failure; @@ -1013,7 +1013,7 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) { long long int number; - if (anyType == NULL || *anyType != NULL) { + if (!anyType || *anyType) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1024,7 +1024,7 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) (*anyType)->node = xmlCopyNode(node, 1); - if ((*anyType)->node == NULL) { + if (!(*anyType)->node) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not copy an XML node")); goto failure; @@ -1035,7 +1035,7 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) (node, BAD_CAST "type", BAD_CAST "http://www.w3.org/2001/XMLSchema-instance"); - if ((*anyType)->other == NULL) { + if (!(*anyType)->other) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("AnyType is missing 'type' property")); goto failure; @@ -1153,7 +1153,7 @@ esxVI_String_ListContainsValue(esxVI_String *stringList, const char *value) { esxVI_String *string; - for (string = stringList; string != NULL; string = string->_next) { + for (string = stringList; string; string = string->_next) { if (STREQ(string->value, value)) { return true; } @@ -1196,7 +1196,7 @@ esxVI_String_AppendValueListToList(esxVI_String **stringList, esxVI_String *stringListToAppend = NULL; const char *value = valueList; - while (value != NULL && *value != '\0') { + while (value && *value != '\0') { if (esxVI_String_AppendValueToList(&stringListToAppend, value) < 0) { goto failure; } @@ -1228,12 +1228,12 @@ ESX_VI__TEMPLATE__LIST__DEEP_COPY(String) int esxVI_String_DeepCopyValue(char **dest, const char *src) { - if (dest == NULL || *dest != NULL) { + if (!dest || *dest) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (src == NULL) { + if (!src) { return 0; } @@ -1250,7 +1250,7 @@ int esxVI_String_Serialize(esxVI_String *string, const char *element, virBufferPtr output) { - return esxVI_String_SerializeValue(string != NULL ? string->value : NULL, + return esxVI_String_SerializeValue(string ? string->value : NULL, element, output); } @@ -1261,12 +1261,12 @@ int esxVI_String_SerializeValue(const char *value, const char *element, virBufferPtr output) { - if (element == NULL || output == NULL) { + if (!element || !output) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (value == NULL) { + if (!value) { return 0; } @@ -1282,7 +1282,7 @@ esxVI_String_SerializeValue(const char *value, const char *element, int esxVI_String_Deserialize(xmlNodePtr node, esxVI_String **string) { - if (string == NULL || *string != NULL) { + if (!string || *string) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1306,7 +1306,7 @@ ESX_VI__TEMPLATE__LIST__DESERIALIZE(String) int esxVI_String_DeserializeValue(xmlNodePtr node, char **value) { - if (value == NULL || *value != NULL) { + if (!value || *value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1481,7 +1481,7 @@ ESX_VI__TEMPLATE__SERIALIZE(DateTime, int esxVI_DateTime_Deserialize(xmlNodePtr node, esxVI_DateTime **dateTime) { - if (dateTime == NULL || *dateTime != NULL) { + if (!dateTime || *dateTime) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1493,7 +1493,7 @@ esxVI_DateTime_Deserialize(xmlNodePtr node, esxVI_DateTime **dateTime) (*dateTime)->value = (char *)xmlNodeListGetString(node->doc, node->children, 1); - if ((*dateTime)->value == NULL) { + if (!(*dateTime)->value) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("XML node doesn't contain text, expecting an " "xsd:dateTime value")); @@ -1521,12 +1521,12 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime, int tz_minutes; int tz_offset = 0; - if (dateTime == NULL || secondsSinceEpoch == NULL) { + if (!dateTime || !secondsSinceEpoch) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (virStrcpyStatic(value, dateTime->value) == NULL) { + if (!virStrcpyStatic(value, dateTime->value)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("xsd:dateTime value '%s' too long for destination"), dateTime->value); @@ -1548,7 +1548,7 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime, tmp = strptime(value, "%Y-%m-%dT%H:%M:%S", &tm); - if (tmp == NULL) { + if (!tmp) { virReportError(VIR_ERR_INTERNAL_ERROR, _("xsd:dateTime value '%s' has unexpected format"), dateTime->value); @@ -1655,7 +1655,7 @@ ESX_VI__TEMPLATE__FREE(MethodFault, int esxVI_MethodFault_Deserialize(xmlNodePtr node, esxVI_MethodFault **methodFault) { - if (methodFault == NULL || *methodFault != NULL) { + if (!methodFault || *methodFault) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1668,7 +1668,7 @@ esxVI_MethodFault_Deserialize(xmlNodePtr node, esxVI_MethodFault **methodFault) (char *)xmlGetNsProp(node, BAD_CAST "type", BAD_CAST "http://www.w3.org/2001/XMLSchema-instance"); - if ((*methodFault)->_actualType == NULL) { + if (!(*methodFault)->_actualType) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("MethodFault is missing 'type' property")); goto failure; @@ -1721,12 +1721,12 @@ esxVI_ManagedObjectReference_Serialize (esxVI_ManagedObjectReference *managedObjectReference, const char *element, virBufferPtr output) { - if (element == NULL || output == NULL) { + if (!element || !output) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (managedObjectReference == NULL) { + if (!managedObjectReference) { return 0; } @@ -1751,7 +1751,7 @@ int esxVI_ManagedObjectReference_Deserialize (xmlNodePtr node, esxVI_ManagedObjectReference **managedObjectReference) { - if (managedObjectReference == NULL || *managedObjectReference != NULL) { + if (!managedObjectReference || *managedObjectReference) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } @@ -1763,7 +1763,7 @@ esxVI_ManagedObjectReference_Deserialize (*managedObjectReference)->type = (char *)xmlGetNoNsProp(node, BAD_CAST "type"); - if ((*managedObjectReference)->type == NULL) { + if (!(*managedObjectReference)->type) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("ManagedObjectReference is missing 'type' property")); goto failure; @@ -1841,7 +1841,7 @@ ESX_VI__TEMPLATE__DESERIALIZE_EXTRA(Event, /* nothing */, (char *)xmlGetNsProp(node, BAD_CAST "type", BAD_CAST "http://www.w3.org/2001/XMLSchema-instance"); - if ((*ptrptr)->_actualType == NULL) { + if (!(*ptrptr)->_actualType) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s is missing 'type' property"), esxVI_Type_ToString((*ptrptr)->_type)); -- 1.8.1.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list