提交 c03ae952 编写于 作者: M Michal Privoznik

Adapt to VIR_STRDUP and VIR_STRNDUP in src/test/*

上级 3cef9f6a
......@@ -219,18 +219,17 @@ testBuildCapabilities(virConnectPtr conn) {
caps->host.nsecModels = 1;
if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0)
goto no_memory;
caps->host.secModels[0].model = strdup("testSecurity");
if (!caps->host.secModels[0].model)
goto no_memory;
if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0)
goto error;
caps->host.secModels[0].doi = strdup("");
if (!caps->host.secModels[0].doi)
goto no_memory;
if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0)
goto error;
return caps;
no_memory:
virReportOOMError();
error:
virObjectUnref(caps);
return NULL;
}
......@@ -673,10 +672,14 @@ static char *testBuildFilename(const char *relativeTo,
const char *filename) {
char *offset;
int baseLen;
char *ret;
if (!filename || filename[0] == '\0')
return NULL;
if (filename[0] == '/')
return strdup(filename);
if (filename[0] == '/') {
ignore_value(VIR_STRDUP(ret, filename));
return ret;
}
offset = strrchr(relativeTo, '/');
if ((baseLen = (offset-relativeTo+1))) {
......@@ -691,7 +694,8 @@ static char *testBuildFilename(const char *relativeTo,
strcat(absFile, filename);
return absFile;
} else {
return strdup(filename);
ignore_value(VIR_STRDUP(ret, filename));
return ret;
}
}
......@@ -754,13 +758,8 @@ static int testOpenVolumesForPool(xmlDocPtr xml,
}
}
if (def->key == NULL) {
def->key = strdup(def->target.path);
if (def->key == NULL) {
virReportOOMError();
goto error;
}
}
if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0)
goto error;
pool->def->allocation += def->allocation;
pool->def->available = (pool->def->capacity -
......@@ -826,10 +825,8 @@ static int testOpenFromFile(virConnectPtr conn,
privconn->nextDomID = 1;
privconn->numCells = 0;
if ((privconn->path = strdup(file)) == NULL) {
virReportOOMError();
if (VIR_STRDUP(privconn->path, file) < 0)
goto error;
}
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
nodeInfo = &privconn->nodeInfo;
......@@ -2066,9 +2063,9 @@ cleanup:
}
static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
char *ret = strdup("linux");
if (!ret)
virReportOOMError();
char *ret;
ignore_value(VIR_STRDUP(ret, "linux"));
return ret;
}
......@@ -2726,9 +2723,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
if (nparams)
*nparams = 1;
type = strdup("fair");
if (!type)
virReportOOMError();
ignore_value(VIR_STRDUP(type, "fair"));
return type;
}
......@@ -3026,9 +3021,9 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n
for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
virNetworkObjLock(privconn->networks.objs[i]);
if (virNetworkObjIsActive(privconn->networks.objs[i]) &&
!(names[n++] = strdup(privconn->networks.objs[i]->def->name))) {
VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) < 0) {
virNetworkObjUnlock(privconn->networks.objs[i]);
goto no_memory;
goto error;
}
virNetworkObjUnlock(privconn->networks.objs[i]);
}
......@@ -3036,8 +3031,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n
return n;
no_memory:
virReportOOMError();
error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
......@@ -3069,9 +3063,9 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names
for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
virNetworkObjLock(privconn->networks.objs[i]);
if (!virNetworkObjIsActive(privconn->networks.objs[i]) &&
!(names[n++] = strdup(privconn->networks.objs[i]->def->name))) {
VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) < 0) {
virNetworkObjUnlock(privconn->networks.objs[i]);
goto no_memory;
goto error;
}
virNetworkObjUnlock(privconn->networks.objs[i]);
}
......@@ -3079,8 +3073,7 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names
return n;
no_memory:
virReportOOMError();
error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
......@@ -3387,10 +3380,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
goto cleanup;
}
if (!(bridge = strdup(privnet->def->bridge))) {
virReportOOMError();
goto cleanup;
}
ignore_value(VIR_STRDUP(bridge, privnet->def->bridge));
cleanup:
if (privnet)
......@@ -3500,9 +3490,9 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int
for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) {
virInterfaceObjLock(privconn->ifaces.objs[i]);
if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) {
if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) {
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
goto no_memory;
goto error;
}
}
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
......@@ -3511,8 +3501,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int
return n;
no_memory:
virReportOOMError();
error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
......@@ -3546,9 +3535,9 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam
for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) {
virInterfaceObjLock(privconn->ifaces.objs[i]);
if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) {
if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) {
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
goto no_memory;
goto error;
}
}
virInterfaceObjUnlock(privconn->ifaces.objs[i]);
......@@ -3557,8 +3546,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam
return n;
no_memory:
virReportOOMError();
error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
......@@ -3886,13 +3874,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) {
pool->def->allocation = defaultPoolAlloc;
pool->def->available = defaultPoolCap - defaultPoolAlloc;
pool->configFile = strdup("\0");
if (!pool->configFile) {
virReportOOMError();
return -1;
}
return 0;
return VIR_STRDUP(pool->configFile, "");
}
static virDrvOpenStatus testStorageOpen(virConnectPtr conn,
......@@ -3995,9 +3977,9 @@ testConnectListStoragePools(virConnectPtr conn,
for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
virStoragePoolObjLock(privconn->pools.objs[i]);
if (virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
!(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) {
virStoragePoolObjUnlock(privconn->pools.objs[i]);
goto no_memory;
goto error;
}
virStoragePoolObjUnlock(privconn->pools.objs[i]);
}
......@@ -4005,8 +3987,7 @@ testConnectListStoragePools(virConnectPtr conn,
return n;
no_memory:
virReportOOMError();
error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
......@@ -4042,9 +4023,9 @@ testConnectListDefinedStoragePools(virConnectPtr conn,
for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
virStoragePoolObjLock(privconn->pools.objs[i]);
if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
!(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) {
virStoragePoolObjUnlock(privconn->pools.objs[i]);
goto no_memory;
goto error;
}
virStoragePoolObjUnlock(privconn->pools.objs[i]);
}
......@@ -4052,8 +4033,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn,
return n;
no_memory:
virReportOOMError();
error:
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
testDriverUnlock(privconn);
......@@ -4184,9 +4164,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
switch (pool_type) {
case VIR_STORAGE_POOL_LOGICAL:
ret = strdup(defaultPoolSourcesLogicalXML);
if (!ret)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
break;
case VIR_STORAGE_POOL_NETFS:
......@@ -4654,10 +4632,8 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
}
for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) {
if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
virReportOOMError();
if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0)
goto cleanup;
}
}
virStoragePoolObjUnlock(privpool);
......@@ -4916,11 +4892,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
goto cleanup;
}
privvol->key = strdup(privvol->target.path);
if (privvol->key == NULL) {
virReportOOMError();
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup;
}
privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity -
......@@ -5011,11 +4984,8 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup;
}
privvol->key = strdup(privvol->target.path);
if (privvol->key == NULL) {
virReportOOMError();
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup;
}
privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity -
......@@ -5239,9 +5209,7 @@ testStorageVolGetPath(virStorageVolPtr vol) {
goto cleanup;
}
ret = strdup(privvol->target.path);
if (ret == NULL)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, privvol->target.path));
cleanup:
if (privpool)
......@@ -5308,7 +5276,7 @@ testNodeListDevices(virConnectPtr conn,
virNodeDeviceObjLock(driver->devs.objs[i]);
if (cap == NULL ||
virNodeDeviceHasCap(driver->devs.objs[i], cap)) {
if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) == NULL) {
if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) {
virNodeDeviceObjUnlock(driver->devs.objs[i]);
goto failure;
}
......@@ -5399,9 +5367,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev)
}
if (obj->def->parent) {
ret = strdup(obj->def->parent);
if (!ret)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, obj->def->parent));
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device"));
......@@ -5466,8 +5432,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
}
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
if (names[ncaps++] == NULL)
if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->type)) < 0)
goto cleanup;
}
ret = ncaps;
......@@ -5520,10 +5485,8 @@ testNodeDeviceCreateXML(virConnectPtr conn,
/* 'name' is supposed to be filled in by the node device backend, which
* we don't have. Use WWPN instead. */
VIR_FREE(def->name);
if (!(def->name = strdup(wwpn))) {
virReportOOMError();
if (VIR_STRDUP(def->name, wwpn) < 0)
goto cleanup;
}
/* Fill in a random 'host' value, since this would also come from
* the backend */
......@@ -5574,11 +5537,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
goto out;
}
parent_name = strdup(obj->def->parent);
if (parent_name == NULL) {
virReportOOMError();
if (VIR_STRDUP(parent_name, obj->def->parent) < 0)
goto out;
}
/* virNodeDeviceGetParentHost will cause the device object's lock to be
* taken, so we have to dup the parent's name and drop the lock
......@@ -5784,10 +5744,8 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED,
virCheckFlags(0, NULL);
if (!(ret = strdup("image/png"))) {
virReportOOMError();
if (VIR_STRDUP(ret, "image/png") < 0)
return NULL;
}
if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0))
VIR_FREE(ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册