+Tue Dec 11 22:56:47 CET 2007 Jim Meyering <meyering@redhat.com>
+
+ Use a variable name as sizeof argument, not a type name.
+ Given code like: T *var = calloc (n, sizeof (T));
+ Convert to this: T *var = calloc (n, sizeof (*var));
+ This first-cut change adjusts all malloc, calloc, and
+ realloc statements.
+ The only binary differences are in remote_internal.c
+ (due to the bug fix) and in xmlrpc.c (due to factorization).
+ * python/libvir.c: As above.
+ * qemud/event.c: Likewise.
+ * qemud/mdns.c: Likewise.
+ * qemud/qemud.c: Likewise.
+ * qemud/remote.c: Likewise.
+ * src/bridge.c: Likewise.
+ * src/buf.c: Likewise.
+ * src/conf.c: Likewise.
+ * src/hash.c: Likewise.
+ * src/iptables.c: Likewise.
+ * src/openvz_conf.c: Likewise.
+ * src/qemu_conf.c: Likewise.
+ * src/qemu_driver.c: Likewise.
+ * src/test.c: Likewise.
+ * src/xen_internal.c: Likewise.
+ * src/xen_unified.c: Likewise.
+ * src/xm_internal.c: Likewise.
+ * src/xml.c: Likewise.
+ * tests/qemuxml2argvtest.c: Likewise.
+ * src/xmlrpc.c (xmlRpcValuePtr): Likewise, and minor factorization.
+ * src/remote_internal.c (remoteAuthMakeCredentials): Use the right
+ type when allocating space for an array of cred _pointers_.
+
Tue Dec 11 22:19:22 CET 2007 Jim Meyering <meyering@redhat.com>
Test libvirtd's config-processing code.
auth.ncredtype = PyList_Size(pycredtype);
if (auth.ncredtype) {
int i;
- auth.credtype = malloc(sizeof(int) * auth.ncredtype);
+ auth.credtype = malloc(sizeof(*auth.credtype) * auth.ncredtype);
if (auth.credtype == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
if (c_retval) {
- names = malloc(sizeof(char *) * c_retval);
+ names = malloc(sizeof(*names) * c_retval);
if (!names) {
Py_INCREF(Py_None);
return (Py_None);
}
if (c_retval) {
- names = malloc(sizeof(char *) * c_retval);
+ names = malloc(sizeof(*names) * c_retval);
if (!names) {
Py_INCREF(Py_None);
return (Py_None);
}
if (c_retval) {
- names = malloc(sizeof(char *) * c_retval);
+ names = malloc(sizeof(*names) * c_retval);
if (!names) {
Py_INCREF(Py_None);
return (Py_None);
goto error;
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
- freeMems = (unsigned long long *)
- malloc(maxCells * sizeof(unsigned long long));
+ freeMems =
+ malloc(maxCells * sizeof(*freeMems));
if (freeMems == NULL)
goto error;
}
*retfds = NULL;
/* Setup the poll file handle data structs */
- if (!(fds = malloc(sizeof(struct pollfd) * nfds)))
+ if (!(fds = malloc(sizeof(*fds) * nfds)))
return -1;
for (i = 0, nfds = 0 ; i < eventLoop.handlesCount ; i++) {
static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED,
int fd, AvahiWatchEvent event, AvahiWatchCallback cb, void *userdata) {
- AvahiWatch *w = malloc(sizeof(AvahiWatch));
+ AvahiWatch *w = malloc(sizeof(*w));
if (!w)
return NULL;
AvahiTimeoutCallback cb,
void *userdata)
{
- AvahiTimeout *t = malloc(sizeof(AvahiTimeout));
+ AvahiTimeout *t = malloc(sizeof(*t));
struct timeval now;
long long nowms, thenms, timeout;
AVAHI_DEBUG("Add timeout %p TV %p", t, tv);
static AvahiPoll *libvirtd_create_poll(void)
{
- AvahiPoll *p = malloc(sizeof(AvahiPoll));
+ AvahiPoll *p = malloc(sizeof(*p));
if (!p)
return NULL;
struct libvirtd_mdns *libvirtd_mdns_new(void)
{
- struct libvirtd_mdns *mdns = malloc(sizeof(struct libvirtd_mdns));
+ struct libvirtd_mdns *mdns = malloc(sizeof(*mdns));
if (!mdns)
return NULL;
memset(mdns, 0, sizeof(*mdns));
}
struct libvirtd_mdns_group *libvirtd_mdns_add_group(struct libvirtd_mdns *mdns, const char *name) {
- struct libvirtd_mdns_group *group = malloc(sizeof(struct libvirtd_mdns_group));
+ struct libvirtd_mdns_group *group = malloc(sizeof(*group));
AVAHI_DEBUG("Adding group '%s'", name);
if (!group)
}
struct libvirtd_mdns_entry *libvirtd_mdns_add_entry(struct libvirtd_mdns_group *group, const char *type, int port) {
- struct libvirtd_mdns_entry *entry = malloc(sizeof(struct libvirtd_mdns_entry));
+ struct libvirtd_mdns_entry *entry = malloc(sizeof(*entry));
AVAHI_DEBUG("Adding entry %s %d to group %s", type, port, group->name);
if (!entry)
static int qemudListenUnix(struct qemud_server *server,
const char *path, int readonly, int auth) {
- struct qemud_socket *sock = calloc(1, sizeof(struct qemud_socket));
+ struct qemud_socket *sock = calloc(1, sizeof(*sock));
struct sockaddr_un addr;
mode_t oldmask;
gid_t oldgrp;
static struct qemud_server *qemudInitialize(int sigread) {
struct qemud_server *server;
- if (!(server = calloc(1, sizeof(struct qemud_server)))) {
+ if (!(server = calloc(1, sizeof(*server)))) {
qemudLog(QEMUD_ERR, "Failed to allocate struct qemud_server");
return NULL;
}
return -1;
}
- client = calloc(1, sizeof(struct qemud_client));
+ client = calloc(1, sizeof(*client));
if (client == NULL)
goto cleanup;
client->magic = QEMUD_CLIENT_MAGIC;
remoteDispatchError (client, req, "nparams too large");
return -2;
}
- params = malloc (sizeof (virSchedParameter) * nparams);
+ params = malloc (sizeof (*params) * nparams);
if (params == NULL) {
remoteDispatchError (client, req, "out of memory allocating array");
return -2;
/* Serialise the scheduler parameters. */
ret->params.params_len = nparams;
- ret->params.params_val = malloc (sizeof (struct remote_sched_param)
+ ret->params.params_val = malloc (sizeof (*(ret->params.params_val))
* nparams);
if (ret->params.params_val == NULL) {
virDomainFree(dom);
remoteDispatchError (client, req, "nparams too large");
return -2;
}
- params = malloc (sizeof (virSchedParameter) * nparams);
+ params = malloc (sizeof (*params) * nparams);
if (params == NULL) {
remoteDispatchError (client, req, "out of memory allocating array");
return -2;
}
/* Allocate buffers to take the results. */
- info = calloc (args->maxinfo, sizeof (virVcpuInfo));
- cpumaps = calloc (args->maxinfo * args->maplen, sizeof (unsigned char));
+ info = calloc (args->maxinfo, sizeof (*info));
+ cpumaps = calloc (args->maxinfo * args->maplen, sizeof (*cpumaps));
info_len = virDomainGetVcpus (dom,
info, args->maxinfo,
/* Allocate the return buffer for info. */
ret->info.info_len = info_len;
- ret->info.info_val = calloc (info_len, sizeof (remote_vcpu_info));
+ ret->info.info_val = calloc (info_len, sizeof (*(ret->info.info_val)));
for (i = 0; i < info_len; ++i) {
ret->info.info_val[i].number = info[i].number;
dname = args->dname == NULL ? NULL : *args->dname;
/* Wacky world of XDR ... */
- uri_out = calloc (1, sizeof (char *));
+ uri_out = calloc (1, sizeof (*uri_out));
r = __virDomainMigratePrepare (client->conn, &cookie, &cookielen,
uri_in, uri_out,
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
ret->names.names_len =
virConnectListDefinedDomains (client->conn,
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
ret->names.names_len =
virConnectListDefinedNetworks (client->conn,
}
/* Allocate return buffer. */
- ret->ids.ids_val = calloc (args->maxids, sizeof (int));
+ ret->ids.ids_val = calloc (args->maxids, sizeof (*(ret->ids.ids_val)));
ret->ids.ids_len = virConnectListDomains (client->conn,
ret->ids.ids_val, args->maxids);
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
ret->names.names_len =
virConnectListNetworks (client->conn,
remote_auth_list_ret *ret)
{
ret->types.types_len = 1;
- if ((ret->types.types_val = calloc (ret->types.types_len, sizeof (remote_auth_type))) == NULL) {
+ if ((ret->types.types_val = calloc (ret->types.types_len, sizeof (*(ret->types.types_val)))) == NULL) {
remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, "auth types");
return -2;
}
return err;
}
- *ctlp = (brControl *)malloc(sizeof(struct _brControl));
+ *ctlp = malloc(sizeof(**ctlp));
if (!*ctlp) {
close(fd);
return ENOMEM;
snprintf(delayStr, sizeof(delayStr), "%d", delay);
- if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
+ if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error;
n = 0;
1 + /* brige name */
1; /* value */
- if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
+ if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error;
n = 0;
size = buf->use + len + 1000;
- newbuf = (char *) realloc(buf->content, size);
+ newbuf = realloc(buf->content, size);
if (newbuf == NULL) return -1;
buf->content = newbuf;
buf->size = size;
{
virConfPtr ret;
- ret = (virConfPtr) calloc(1, sizeof(virConf));
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL);
if ((comm == NULL) && (name == NULL))
return(NULL);
- ret = (virConfEntryPtr) calloc(1, sizeof(virConfEntry));
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL);
ctxt->line);
return(NULL);
}
- ret = (virConfValuePtr) calloc(1, sizeof(virConfValue));
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
if (str != NULL)
}
if (!cur) {
- if (!(cur = malloc(sizeof(virConfEntry)))) {
+ if (!(cur = malloc(sizeof(*cur)))) {
virConfFreeValue(value);
return (-1);
}
if (size <= 0)
size = 256;
- table = malloc(sizeof(virHashTable));
+ table = malloc(sizeof(*table));
if (table) {
table->size = size;
table->nbElems = 0;
- table->table = calloc(1, size * sizeof(virHashEntry));
+ table->table = calloc(1, size * sizeof(*(table->table)));
if (table->table) {
return (table);
}
if (oldtable == NULL)
return (-1);
- table->table = calloc(1, size * sizeof(virHashEntry));
+ table->table = calloc(1, size * sizeof(*(table->table)));
if (table->table == NULL) {
table->table = oldtable;
return (-1);
if (insert == NULL) {
entry = &(table->table[key]);
} else {
- entry = malloc(sizeof(virHashEntry));
+ entry = malloc(sizeof(*entry));
if (entry == NULL)
return (-1);
}
if (insert == NULL) {
entry = &(table->table[key]);
} else {
- entry = malloc(sizeof(virHashEntry));
+ entry = malloc(sizeof(*entry));
if (entry == NULL)
return (-1);
}
virGetConnect(void) {
virConnectPtr ret;
- ret = (virConnectPtr) calloc(1, sizeof(virConnect));
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virHashError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
goto failed;
/*
* not found, allocate a new one
*/
- ret = (virDomainPtr) calloc(1, sizeof(virDomain));
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
goto error;
/*
* not found, allocate a new one
*/
- ret = (virNetworkPtr) calloc(1, sizeof(virNetwork));
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
goto error;
{
iptRule *r;
- if (!(r = (iptRule *)realloc(rules->rules, sizeof(iptRule) * (rules->nrules+1)))) {
+ if (!(r = realloc(rules->rules, sizeof(*r) * (rules->nrules+1)))) {
int i = 0;
while (argv[i])
free(argv[i++]);
{
iptRules *rules;
- if (!(rules = (iptRules *)calloc(1, sizeof (iptRules))))
+ if (!(rules = calloc(1, sizeof (*rules))))
return NULL;
if (!(rules->table = strdup(table)))
2 + /* --table foo */
2; /* --new-chain bar */
- if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
+ if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error;
n = 0;
va_end(args);
- if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
+ if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error;
if (!(rule = (char *)malloc(rulelen)))
{
iptablesContext *ctx;
- if (!(ctx = (iptablesContext *) calloc(1, sizeof (iptablesContext))))
+ if (!(ctx = calloc(1, sizeof (*ctx))))
return NULL;
if (!(ctx->input_filter = iptRulesNew("filter", IPTABLES_PREFIX "INPUT")))
return vm;
}
- if (!(vm = calloc(1, sizeof(struct openvz_vm)))) {
+ if (!(vm = calloc(1, sizeof(*vm)))) {
openvzFreeVMDef(def);
error(conn, VIR_ERR_NO_MEMORY, "vm");
return NULL;
struct ovz_ip *ovzIp;
struct ovz_ns *ovzNs;
- if (!(def = calloc(1, sizeof(struct openvz_vm_def)))) {
+ if (!(def = calloc(1, sizeof(*def)))) {
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
return NULL;
}
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
goto bail_out;
}
- if (!(ovzIp = calloc(1, sizeof(struct ovz_ip)))) {
+ if (!(ovzIp = calloc(1, sizeof(*ovzIp)))) {
openvzLog(OPENVZ_ERR, "Failed to Create Memory for 'ovz_ip' structure");
goto bail_out;
}
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
goto bail_out;
}
- if (!(ovzNs = calloc(1, sizeof(struct ovz_ns)))) {
+ if (!(ovzNs = calloc(1, sizeof(*ovzNs)))) {
openvzLog(OPENVZ_ERR, "Failed to Create Memory for 'ovz_ns' structure");
goto bail_out;
}
}
pnext = &vm;
while(!feof(fp)) {
- *pnext = calloc(1, sizeof(struct openvz_vm));
+ *pnext = calloc(1, sizeof(**pnext));
if(!*pnext) {
error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed");
goto error;
(*pnext)->vpsid = -1;
}
- vmdef = calloc(1, sizeof(struct openvz_vm_def));
+ vmdef = calloc(1, sizeof(*vmdef));
if(!vmdef) {
error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed");
free(*pnext);
int i;
struct qemud_vm_def *def;
- if (!(def = calloc(1, sizeof(struct qemud_vm_def)))) {
+ if (!(def = calloc(1, sizeof(*def)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
return NULL;
}
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_disk_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_disk_def *disk = calloc(1, sizeof(struct qemud_vm_disk_def));
+ struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk));
if (!disk) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "disk");
goto error;
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_net_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_net_def *net = calloc(1, sizeof(struct qemud_vm_net_def));
+ struct qemud_vm_net_def *net = calloc(1, sizeof(*net));
if (!net) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "net");
goto error;
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_input_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_input_def *input = calloc(1, sizeof(struct qemud_vm_input_def));
+ struct qemud_vm_input_def *input = calloc(1, sizeof(*input));
if (!input) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "input");
goto error;
}
if (!hasPS2mouse) {
- input = calloc(1, sizeof(struct qemud_vm_input_def));
+ input = calloc(1, sizeof(*input));
if (!input) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "input");
goto error;
if (!(retval = strdup(tapfdstr)))
goto no_memory;
- if (!(tapfds = realloc(vm->tapfds, sizeof(int) * (vm->ntapfds+2))))
+ if (!(tapfds = realloc(vm->tapfds, sizeof(*tapfds) * (vm->ntapfds+2))))
goto no_memory;
vm->tapfds = tapfds;
snprintf(memory, sizeof(memory), "%d", vm->def->memory/1024);
snprintf(vcpus, sizeof(vcpus), "%d", vm->def->vcpus);
- if (!(*argv = malloc(sizeof(char *) * (len+1))))
+ if (!(*argv = malloc(sizeof(**argv) * (len+1))))
goto no_memory;
if (!((*argv)[++n] = strdup(vm->def->os.binary)))
goto no_memory;
{
xmlDocPtr xml;
xmlNodePtr node;
- struct qemud_vm_device_def *dev = calloc(1, sizeof(struct qemud_vm_device_def));
+ struct qemud_vm_device_def *dev = calloc(1, sizeof(*dev));
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, "device.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
return vm;
}
- if (!(vm = calloc(1, sizeof(struct qemud_vm)))) {
+ if (!(vm = calloc(1, sizeof(*vm)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "vm");
return NULL;
}
continue;
}
- if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) {
+ if (!(range = calloc(1, sizeof(*range)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "range");
return 0;
}
xmlXPathObjectPtr obj = NULL, tmp = NULL;
struct qemud_network_def *def;
- if (!(def = calloc(1, sizeof(struct qemud_network_def)))) {
+ if (!(def = calloc(1, sizeof(*def)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def");
return NULL;
}
return network;
}
- if (!(network = calloc(1, sizeof(struct qemud_network)))) {
+ if (!(network = calloc(1, sizeof(*network)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
return NULL;
}
char *base = NULL;
char driverConf[PATH_MAX];
- if (!(qemu_driver = calloc(1, sizeof(struct qemud_driver)))) {
+ if (!(qemu_driver = calloc(1, sizeof(*qemu_driver)))) {
return -1;
}
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
1; /* NULL */
- if (!(*argv = calloc(len, sizeof(char *))))
+ if (!(*argv = calloc(len, sizeof(**argv))))
goto no_memory;
#define APPEND_ARG(v, n, s) do { \
// Generate the final command argv[] array.
// ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL]
- cmd_argv = malloc (nr_args * sizeof (char *));
+ cmd_argv = malloc (nr_args * sizeof (*cmd_argv));
if (cmd_argv == NULL) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
goto failed;
// Run the external process.
if (!cmd_argv) {
- cmd_argv = malloc (2 * sizeof (char *));
+ cmd_argv = malloc (2 * sizeof (*cmd_argv));
if (cmd_argv == NULL) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
goto failed;
if (inside_daemon)
return VIR_DRV_OPEN_DECLINED;
- priv = malloc (sizeof(struct private_data));
+ priv = malloc (sizeof(*priv));
if (!priv) {
error (conn, VIR_ERR_NO_MEMORY, "struct private_data");
return VIR_DRV_OPEN_ERROR;
/* Serialise the scheduler parameters. */
args.params.params_len = nparams;
- args.params.params_val = malloc (sizeof (struct remote_sched_param)
+ args.params.params_val = malloc (sizeof (*args.params.params_val)
* nparams);
if (args.params.params_val == NULL) {
error (domain->conn, VIR_ERR_RPC, "out of memory allocating array");
* use the UNIX transport. This handles Xen driver
* which doesn't have its own impl of the network APIs.
*/
- struct private_data *priv = malloc (sizeof(struct private_data));
+ struct private_data *priv = malloc (sizeof(*priv));
int ret, rflags = 0;
if (!priv) {
error (conn, VIR_ERR_NO_MEMORY, "struct private_data");
*/
static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
{
- sasl_callback_t *cbs = calloc(ncredtype+1, sizeof (sasl_callback_t));
+ sasl_callback_t *cbs = calloc(ncredtype+1, sizeof (*cbs));
int i, n;
if (!cbs) {
return NULL;
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
; /* empty */
- *cred = calloc(ninteract, sizeof(virConnectCredential));
+ *cred = calloc(ninteract, sizeof(*cred));
if (!*cred)
return -1;
static int testOpenDefault(virConnectPtr conn) {
int u;
struct timeval tv;
- testConnPtr privconn = malloc(sizeof(testConn));
+ testConnPtr privconn = malloc(sizeof(*privconn));
if (!privconn) {
testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
xmlNodePtr *domains, *networks = NULL;
xmlXPathContextPtr ctxt = NULL;
virNodeInfoPtr nodeInfo;
- testConnPtr privconn = malloc(sizeof(testConn));
+ testConnPtr privconn = malloc(sizeof(*privconn));
if (!privconn) {
testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
/*
* xen_internal.c: direct access to Xen hypervisor level
*
- * Copyright (C) 2005, 2006 Red Hat, Inc.
+ * Copyright (C) 2005, 2006, 2007 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
#define XEN_GETDOMAININFOLIST_ALLOC(domlist, size) \
(hypervisor_version < 2 ? \
- ((domlist.v0 = malloc(sizeof(xen_v0_getdomaininfo)*(size))) != NULL) : \
+ ((domlist.v0 = malloc(sizeof(*domlist.v0)*(size))) != NULL) : \
(dom_interface_version < 5 ? \
- ((domlist.v2 = malloc(sizeof(xen_v2_getdomaininfo)*(size))) != NULL) : \
- ((domlist.v2d5 = malloc(sizeof(xen_v2d5_getdomaininfo)*(size))) != NULL)))
+ ((domlist.v2 = malloc(sizeof(*domlist.v2)*(size))) != NULL) : \
+ ((domlist.v2d5 = malloc(sizeof(*domlist.v2d5)*(size))) != NULL)))
#define XEN_GETDOMAININFOLIST_FREE(domlist) \
(hypervisor_version < 2 ? \
free(domlist.v2) : \
free(domlist.v2d5)))
-#define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \
- (hypervisor_version < 2 ? \
- memset(domlist.v0, 0, sizeof(xen_v0_getdomaininfo) * size) : \
- (dom_interface_version < 5 ? \
- memset(domlist.v2, 0, sizeof(xen_v2_getdomaininfo) * size) : \
- memset(domlist.v2d5, 0, sizeof(xen_v2d5_getdomaininfo) * size)))
+#define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \
+ (hypervisor_version < 2 ? \
+ memset(domlist.v0, 0, sizeof(*domlist.v0) * size) : \
+ (dom_interface_version < 5 ? \
+ memset(domlist.v2, 0, sizeof(*domlist.v2) * size) : \
+ memset(domlist.v2d5, 0, sizeof(*domlist.v2d5) * size)))
#define XEN_GETDOMAININFOLIST_DOMAIN(domlist, n) \
(hypervisor_version < 2 ? \
*/
hypervisor_version = 2;
- ipt = malloc(sizeof(virVcpuInfo));
+ ipt = malloc(sizeof(*ipt));
if (ipt == NULL){
#ifdef DEBUG
fprintf(stderr, "Memory allocation failed at xenHypervisorInit()\n");
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return(NULL);
- cpulist = (char *) calloc(nb_cpu, sizeof(char));
+ cpulist = calloc(nb_cpu, sizeof(*cpulist));
if (cpulist == NULL)
goto done;
- cpuinfo = malloc(sizeof(virVcpuInfo) * nb_vcpu);
+ cpuinfo = malloc(sizeof(*cpuinfo) * nb_vcpu);
if (cpuinfo == NULL)
goto done;
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
/* Had better have a name...*/
if (xenXMConfigGetString(conf, "name", &name) < 0) {
virConfValuePtr value;
- value = malloc(sizeof(virConfValue));
+ value = malloc(sizeof(*value));
if (!value) {
return (-1);
}
virConfValuePtr value;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- value = malloc(sizeof(virConfValue));
+ value = malloc(sizeof(*value));
if (!value) {
return (-1);
}
entry->conf = NULL;
} else { /* Completely new entry */
newborn = 1;
- if (!(entry = malloc(sizeof(xenXMConfCache)))) {
+ if (!(entry = malloc(sizeof(*entry)))) {
xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
goto cleanup;
}
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return (-1);
value->type = VIR_CONF_LONG;
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return (-1);
value->type = VIR_CONF_LONG;
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return (-1);
value->type = VIR_CONF_LONG;
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
virConfValuePtr value = NULL;
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return -1;
value->type = VIR_CONF_LONG;
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL;
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return -1;
value->type = VIR_CONF_STRING;
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
- if (!(vfb = malloc(sizeof(virConfValue)))) {
+ if (!(vfb = malloc(sizeof(*vfb)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
xmlFree(type);
if (val) {
virConfValuePtr disp;
- if (!(disp = malloc(sizeof(virConfValue)))) {
+ if (!(disp = malloc(sizeof(*disp)))) {
free(val);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr disks;
- if (!(disks = malloc(sizeof(virConfValue)))) {
+ if (!(disks = malloc(sizeof(*disks)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, priv->xendConfigVersion, &disk) < 0)
goto error;
if (disk) {
- if (!(thisDisk = malloc(sizeof(virConfValue)))) {
+ if (!(thisDisk = malloc(sizeof(*thisDisk)))) {
free(disk);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr vifs;
- if (!(vifs = malloc(sizeof(virConfValue)))) {
+ if (!(vifs = malloc(sizeof(*vifs)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm);
if (!vif)
goto error;
- if (!(thisVif = malloc(sizeof(virConfValue)))) {
+ if (!(thisVif = malloc(sizeof(*thisVif)))) {
if (vif)
free(vif);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
- if (!(entry = calloc(1, sizeof(xenXMConfCache)))) {
+ if (!(entry = calloc(1, sizeof(*entry)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
if ((str == NULL) || (xml == NULL) || (maxcpu <= 0) || (maxcpu > 100000))
return (-1);
- cpuset = malloc(maxcpu * sizeof(char));
+ cpuset = malloc(maxcpu * sizeof(*cpuset));
if (cpuset == NULL)
goto memory_error;
if (maxcpu <= 0)
maxcpu = 4096;
- cpuset = calloc(maxcpu, sizeof(char));
+ cpuset = calloc(maxcpu, sizeof(*cpuset));
if (cpuset == NULL) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
return(NULL);
ret = obj->nodesetval->nodeNr;
if (list != NULL) {
- *list = malloc(ret * sizeof(xmlNodePtr));
+ *list = malloc(ret * sizeof(**list));
if (*list == NULL) {
virXMLError(NULL, VIR_ERR_NO_MEMORY,
_("allocate string array"),
- ret * sizeof(xmlNodePtr));
+ ret * sizeof(**list));
} else {
memcpy(*list, obj->nodesetval->nodeTab,
ret * sizeof(xmlNodePtr));
* it in a range format guaranteed to be understood by Xen.
*/
if (maxcpu > 0) {
- cpuset = malloc(maxcpu * sizeof(char));
+ cpuset = malloc(maxcpu * sizeof(*cpuset));
if (cpuset != NULL) {
res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
if (res > 0) {
xmlRpcValuePtr ret = xmlRpcValueNew(XML_RPC_ARRAY);
xmlNodePtr cur;
int n_elements = 0;
+ xmlRpcValuePtr *elems;
if (!ret)
return NULL;
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur))
n_elements += 1;
- ret->value.array.elements = malloc(n_elements * sizeof(xmlRpcValue));
- if (!ret->value.array.elements) {
+ elems = malloc(n_elements * sizeof(*elems));
+ if (!elems) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value array"),
- n_elements * sizeof(xmlRpcValue));
+ n_elements * sizeof(*elems));
free(ret);
return NULL;
}
n_elements = 0;
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur)) {
- ret->value.array.elements[n_elements] = xmlRpcValueUnmarshal(cur);
+ elems[n_elements] = xmlRpcValueUnmarshal(cur);
n_elements += 1;
}
+ ret->value.array.elements = elems;
ret->value.array.n_elements = n_elements;
return ret;
len += strlen(*tmp) + 1;
tmp++;
}
- actualargv = malloc(sizeof(char)*len);
+ actualargv = malloc(sizeof(*actualargv)*len);
actualargv[0] = '\0';
tmp = argv;
len = 0;