mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Use virAsprintf, rather than VIR_ALLOC + strcpy + strcat
This commit is contained in:
parent
bb175dfc53
commit
adf4384501
@ -1,3 +1,10 @@
|
||||
Tue May 19 09:14:12 EDT 2009 Cole Robinson <crobinso@redhat.com>
|
||||
|
||||
Use virAsprintf, rather than VIR_ALLOC + strcpy + strcat
|
||||
* qemud/remote.c src/remote_internal.c src/storage_backend.c
|
||||
src/storage_backend_fs.c src/storage_backend_logical.c
|
||||
src/test.c
|
||||
|
||||
Tue May 19 09:04:05 EDT 2009 Cole Robinson <crobinso@redhat.com>
|
||||
|
||||
* src/virsh.c: Don't validate disk type in virsh attach-disk
|
||||
|
@ -52,7 +52,9 @@
|
||||
#include "datatypes.h"
|
||||
#include "qemud.h"
|
||||
#include "memory.h"
|
||||
#include "util.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_REMOTE
|
||||
#define REMOTE_DEBUG(fmt, ...) DEBUG(fmt, __VA_ARGS__)
|
||||
|
||||
static void remoteDispatchFormatError (remote_error *rerr,
|
||||
@ -2602,14 +2604,11 @@ static char *addrToString(remote_error *rerr,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) {
|
||||
remoteDispatchOOMError(rerr);
|
||||
if (virAsprintf(&addr, "%s;%s", host, port) == -1) {
|
||||
virReportOOMError(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(addr, host);
|
||||
strcat(addr, ";");
|
||||
strcat(addr, port);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -5189,14 +5189,11 @@ static char *addrToString(struct sockaddr_storage *sa, socklen_t salen)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) {
|
||||
virReportOOMError (NULL);
|
||||
if (virAsprintf(&addr, "%s;%s", host, port) == -1) {
|
||||
virReportOOMError(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(addr, host);
|
||||
strcat(addr, ";");
|
||||
strcat(addr, port);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -342,17 +342,14 @@ virStorageBackendStablePath(virConnectPtr conn,
|
||||
if (dent->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) +
|
||||
1 + strlen(dent->d_name) + 1) < 0) {
|
||||
if (virAsprintf(&stablepath, "%s/%s",
|
||||
pool->def->target.path,
|
||||
dent->d_name) == -1) {
|
||||
virReportOOMError(conn);
|
||||
closedir(dh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(stablepath, pool->def->target.path);
|
||||
strcat(stablepath, "/");
|
||||
strcat(stablepath, dent->d_name);
|
||||
|
||||
if (virFileLinkPointsTo(stablepath, devpath)) {
|
||||
closedir(dh);
|
||||
return stablepath;
|
||||
|
@ -668,14 +668,13 @@ virStorageBackendFileSystemMount(virConnectPtr conn,
|
||||
}
|
||||
|
||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
||||
if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
|
||||
1 + strlen(pool->def->source.dir) + 1) < 0) {
|
||||
if (virAsprintf(&src, "%s:%s",
|
||||
pool->def->source.host.name,
|
||||
pool->def->source.dir) == -1) {
|
||||
virReportOOMError(conn);
|
||||
return -1;
|
||||
}
|
||||
strcpy(src, pool->def->source.host.name);
|
||||
strcat(src, ":");
|
||||
strcat(src, pool->def->source.dir);
|
||||
|
||||
} else {
|
||||
if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
|
||||
virReportOOMError(conn);
|
||||
@ -829,13 +828,11 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
||||
|
||||
vol->type = VIR_STORAGE_VOL_FILE;
|
||||
vol->target.format = VIR_STORAGE_VOL_FILE_RAW; /* Real value is filled in during probe */
|
||||
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||
1 + strlen(vol->name) + 1) < 0)
|
||||
if (virAsprintf(&vol->target.path, "%s/%s",
|
||||
pool->def->target.path,
|
||||
vol->name) == -1)
|
||||
goto no_memory;
|
||||
|
||||
strcpy(vol->target.path, pool->def->target.path);
|
||||
strcat(vol->target.path, "/");
|
||||
strcat(vol->target.path, vol->name);
|
||||
if ((vol->key = strdup(vol->target.path)) == NULL)
|
||||
goto no_memory;
|
||||
|
||||
@ -995,15 +992,15 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
||||
virStorageVolDefPtr vol)
|
||||
{
|
||||
|
||||
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||
1 + strlen(vol->name) + 1) < 0) {
|
||||
vol->type = VIR_STORAGE_VOL_FILE;
|
||||
|
||||
if (virAsprintf(&vol->target.path, "%s/%s",
|
||||
pool->def->target.path,
|
||||
vol->name) == -1) {
|
||||
virReportOOMError(conn);
|
||||
return -1;
|
||||
}
|
||||
vol->type = VIR_STORAGE_VOL_FILE;
|
||||
strcpy(vol->target.path, pool->def->target.path);
|
||||
strcat(vol->target.path, "/");
|
||||
strcat(vol->target.path, vol->name);
|
||||
|
||||
vol->key = strdup(vol->target.path);
|
||||
if (vol->key == NULL) {
|
||||
virReportOOMError(conn);
|
||||
|
@ -594,14 +594,13 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
|
||||
/* A target path passed to CreateVol has no meaning */
|
||||
VIR_FREE(vol->target.path);
|
||||
}
|
||||
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||
1 + strlen(vol->name) + 1) < 0) {
|
||||
|
||||
if (virAsprintf(&vol->target.path, "%s/%s",
|
||||
pool->def->target.path,
|
||||
vol->name) == -1) {
|
||||
virReportOOMError(conn);
|
||||
return -1;
|
||||
}
|
||||
strcpy(vol->target.path, pool->def->target.path);
|
||||
strcat(vol->target.path, "/");
|
||||
strcat(vol->target.path, vol->name);
|
||||
|
||||
if (virRun(conn, cmdargv, NULL) < 0)
|
||||
return -1;
|
||||
|
18
src/test.c
18
src/test.c
@ -3110,16 +3110,13 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(privvol->target.path,
|
||||
strlen(privpool->def->target.path) +
|
||||
1 + strlen(privvol->name) + 1) < 0) {
|
||||
if (virAsprintf(&privvol->target.path, "%s/%s",
|
||||
privpool->def->target.path,
|
||||
privvol->name) == -1) {
|
||||
virReportOOMError(pool->conn);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
strcpy(privvol->target.path, privpool->def->target.path);
|
||||
strcat(privvol->target.path, "/");
|
||||
strcat(privvol->target.path, privvol->name);
|
||||
privvol->key = strdup(privvol->target.path);
|
||||
if (privvol->key == NULL) {
|
||||
virReportOOMError(pool->conn);
|
||||
@ -3204,16 +3201,13 @@ testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(privvol->target.path,
|
||||
strlen(privpool->def->target.path) +
|
||||
1 + strlen(privvol->name) + 1) < 0) {
|
||||
if (virAsprintf(&privvol->target.path, "%s/%s",
|
||||
privpool->def->target.path,
|
||||
privvol->name) == -1) {
|
||||
virReportOOMError(pool->conn);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
strcpy(privvol->target.path, privpool->def->target.path);
|
||||
strcat(privvol->target.path, "/");
|
||||
strcat(privvol->target.path, privvol->name);
|
||||
privvol->key = strdup(privvol->target.path);
|
||||
if (privvol->key == NULL) {
|
||||
virReportOOMError(pool->conn);
|
||||
|
Loading…
x
Reference in New Issue
Block a user