Since no one objected to my suggestion here:
http://thread.gmane.org/gmane.comp.emulators.libvirt/3956/focus=4039
Given code like T *var = calloc (n, sizeof (T));
I prefer this: T *var = calloc (n, sizeof (*var));
I've gone ahead with some first steps.
With the patch below, there are only two .o files with differences.
Mainly for my own reference, here's what I did:
make CFLAGS=-g
mkdir ../obj
for i in $(find . -name '*.o'); do cp -l --parents $i ../obj;done
make clean
patch -p1 < this-patch
make CFLAGS=-g
for i in $(find . -name '*.o'); do cmp $i ../obj/$i;done
The first difference was due to my minor factorization in xmlrpc.c.
That was expected. However, the second was not. The calloc stmt
below (from remote_internal.c) applies sizeof to the wrong type:
static int remoteAuthMakeCredentials(sasl_interact_t *interact,
virConnectCredentialPtr *cred)
{
int ninteract;
if (!cred)
return -1;
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
; /* empty */
*cred = calloc(ninteract, sizeof(virConnectCredential));
if (!*cred)
------------------------
We're lucky virConnectCredential is not smaller than sizeof void*.
If it had been, this would have been a real bug, rather than just an
over-allocation.
I've also removed all casts of malloc, realloc, calloc return values
on the touched lines, since they are universally unnecessary.
-----------------------
Subject: [PATCH] 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_.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
ChangeLog | 25 +++++++++++++++++++++++++
python/libvir.c | 12 ++++++------
qemud/event.c | 2 +-
qemud/mdns.c | 12 ++++++------
qemud/qemud.c | 6 +++---
qemud/remote.c | 24 ++++++++++++------------
src/bridge.c | 6 +++---
src/buf.c | 2 +-
src/conf.c | 8 ++++----
src/hash.c | 16 ++++++++--------
src/iptables.c | 10 +++++-----
src/openvz_conf.c | 12 ++++++------
src/qemu_conf.c | 24 ++++++++++++------------
src/qemu_driver.c | 4 ++--
src/remote_internal.c | 14 +++++++-------
src/test.c | 4 ++--
src/xen_internal.c | 22 +++++++++++-----------
src/xen_unified.c | 4 ++--
src/xm_internal.c | 30 +++++++++++++++---------------
src/xml.c | 10 +++++-----
src/xmlrpc.c | 10 ++++++----
tests/qemuxml2argvtest.c | 2 +-
22 files changed, 143 insertions(+), 116 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index efc765b..8a6526c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2007-12-11 Jim Meyering <meyering(a)redhat.com>
+
+ Change RHS of T *V = *alloc (sizeof (T) to *alloc (sizeof *V)
+ * python/libvir.c:
+ * qemud/event.c:
+ * qemud/mdns.c:
+ * qemud/qemud.c:
+ * qemud/remote.c:
+ * src/bridge.c:
+ * src/buf.c:
+ * src/conf.c:
+ * src/hash.c:
+ * src/iptables.c:
+ * src/openvz_conf.c:
+ * src/qemu_conf.c:
+ * src/qemu_driver.c:
+ * src/remote_internal.c:
+ * src/test.c:
+ * src/xen_internal.c:
+ * src/xen_unified.c:
+ * src/xm_internal.c:
+ * src/xml.c:
+ * src/xmlrpc.c:
+ * tests/qemuxml2argvtest.c:
+
Mon Dec 10 19:25:22 CET 2007 Jim Meyering <meyering(a)redhat.com>
Add gnulib-tool unit tests.
diff --git a/python/libvir.c b/python/libvir.c
index 0edec41..3b41dc1 100644
--- a/python/libvir.c
+++ b/python/libvir.c
@@ -347,7 +347,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject
*args) {
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);
@@ -490,7 +490,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
}
if (c_retval) {
- names = malloc(sizeof(char *) * c_retval);
+ names = malloc(sizeof(*names) * c_retval);
if (!names) {
Py_INCREF(Py_None);
return (Py_None);
@@ -670,7 +670,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
}
if (c_retval) {
- names = malloc(sizeof(char *) * c_retval);
+ names = malloc(sizeof(*names) * c_retval);
if (!names) {
Py_INCREF(Py_None);
return (Py_None);
@@ -717,7 +717,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self
ATTRIBUTE_UNUSED,
}
if (c_retval) {
- names = malloc(sizeof(char *) * c_retval);
+ names = malloc(sizeof(*names) * c_retval);
if (!names) {
Py_INCREF(Py_None);
return (Py_None);
@@ -863,8 +863,8 @@ PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self
ATTRIBUTE_UNUSED,
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;
diff --git a/qemud/event.c b/qemud/event.c
index 1faeaf1..b7d75a0 100644
--- a/qemud/event.c
+++ b/qemud/event.c
@@ -281,7 +281,7 @@ static int virEventMakePollFDs(struct pollfd **retfds) {
}
*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++) {
diff --git a/qemud/mdns.c b/qemud/mdns.c
index bd1f548..1585b5b 100644
--- a/qemud/mdns.c
+++ b/qemud/mdns.c
@@ -239,7 +239,7 @@ static void libvirtd_mdns_watch_dispatch(int fd, int events, void
*opaque)
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;
@@ -289,7 +289,7 @@ static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api
ATTRIBUTE_UN
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);
@@ -359,7 +359,7 @@ static void libvirtd_mdns_timeout_free(AvahiTimeout *t)
static AvahiPoll *libvirtd_create_poll(void)
{
- AvahiPoll *p = malloc(sizeof(AvahiPoll));
+ AvahiPoll *p = malloc(sizeof(*p));
if (!p)
return NULL;
@@ -379,7 +379,7 @@ static AvahiPoll *libvirtd_create_poll(void)
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));
@@ -408,7 +408,7 @@ int libvirtd_mdns_start(struct libvirtd_mdns *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)
@@ -444,7 +444,7 @@ void libvirtd_mdns_remove_group(struct libvirtd_mdns *mdns, struct
libvirtd_mdns
}
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)
diff --git a/qemud/qemud.c b/qemud/qemud.c
index 9794c03..5360cf8 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -460,7 +460,7 @@ static int qemudWritePidFile(const char *pidFile) {
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;
@@ -703,7 +703,7 @@ static int qemudInitPaths(struct qemud_server *server,
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;
}
@@ -1043,7 +1043,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
return -1;
}
- client = calloc(1, sizeof(struct qemud_client));
+ client = calloc(1, sizeof(*client));
if (client == NULL)
goto cleanup;
client->magic = QEMUD_CLIENT_MAGIC;
diff --git a/qemud/remote.c b/qemud/remote.c
index 8c07b95..b5b0ef6 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -639,7 +639,7 @@ remoteDispatchDomainGetSchedulerParameters (struct qemud_server
*server ATTRIBUT
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;
@@ -661,7 +661,7 @@ remoteDispatchDomainGetSchedulerParameters (struct qemud_server
*server ATTRIBUT
/* 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);
@@ -726,7 +726,7 @@ remoteDispatchDomainSetSchedulerParameters (struct qemud_server
*server ATTRIBUT
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;
@@ -1158,8 +1158,8 @@ remoteDispatchDomainGetVcpus (struct qemud_server *server
ATTRIBUTE_UNUSED,
}
/* 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,
@@ -1171,7 +1171,7 @@ remoteDispatchDomainGetVcpus (struct qemud_server *server
ATTRIBUTE_UNUSED,
/* 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;
@@ -1210,7 +1210,7 @@ remoteDispatchDomainMigratePrepare (struct qemud_server *server
ATTRIBUTE_UNUSED
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,
@@ -1295,7 +1295,7 @@ remoteDispatchListDefinedDomains (struct qemud_server *server
ATTRIBUTE_UNUSED,
}
/* 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,
@@ -1703,7 +1703,7 @@ remoteDispatchListDefinedNetworks (struct qemud_server *server
ATTRIBUTE_UNUSED,
}
/* 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,
@@ -1729,7 +1729,7 @@ remoteDispatchListDomains (struct qemud_server *server
ATTRIBUTE_UNUSED,
}
/* 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);
@@ -1754,7 +1754,7 @@ remoteDispatchListNetworks (struct qemud_server *server
ATTRIBUTE_UNUSED,
}
/* 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,
@@ -2062,7 +2062,7 @@ remoteDispatchAuthList (struct qemud_server *server
ATTRIBUTE_UNUSED,
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;
}
diff --git a/src/bridge.c b/src/bridge.c
index 5badc21..caa6ebf 100644
--- a/src/bridge.c
+++ b/src/bridge.c
@@ -83,7 +83,7 @@ brInit(brControl **ctlp)
return err;
}
- *ctlp = (brControl *)malloc(sizeof(struct _brControl));
+ *ctlp = malloc(sizeof(**ctlp));
if (!*ctlp) {
close(fd);
return ENOMEM;
@@ -680,7 +680,7 @@ brSetForwardDelay(brControl *ctl ATTRIBUTE_UNUSED,
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;
@@ -737,7 +737,7 @@ brSetEnableSTP(brControl *ctl ATTRIBUTE_UNUSED,
1 + /* brige name */
1; /* value */
- if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
+ if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error;
n = 0;
diff --git a/src/buf.c b/src/buf.c
index 5b7f15d..0229be9 100644
--- a/src/buf.c
+++ b/src/buf.c
@@ -40,7 +40,7 @@ virBufferGrow(virBufferPtr buf, unsigned int len)
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;
diff --git a/src/conf.c b/src/conf.c
index 4c725bf..8190de1 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -152,7 +152,7 @@ __virConfNew(void)
{
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);
@@ -201,7 +201,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value,
char *comm)
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);
@@ -486,7 +486,7 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
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)
@@ -837,7 +837,7 @@ __virConfSetValue (virConfPtr conf,
}
if (!cur) {
- if (!(cur = malloc(sizeof(virConfEntry)))) {
+ if (!(cur = malloc(sizeof(*cur)))) {
virConfFreeValue(value);
return (-1);
}
diff --git a/src/hash.c b/src/hash.c
index b7962d9..8f322f1 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -87,11 +87,11 @@ virHashCreate(int size)
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);
}
@@ -133,7 +133,7 @@ virHashGrow(virHashTablePtr table, int size)
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);
@@ -279,7 +279,7 @@ virHashAddEntry(virHashTablePtr table, const char *name, void
*userdata)
if (insert == NULL) {
entry = &(table->table[key]);
} else {
- entry = malloc(sizeof(virHashEntry));
+ entry = malloc(sizeof(*entry));
if (entry == NULL)
return (-1);
}
@@ -352,7 +352,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
if (insert == NULL) {
entry = &(table->table[key]);
} else {
- entry = malloc(sizeof(virHashEntry));
+ entry = malloc(sizeof(*entry));
if (entry == NULL)
return (-1);
}
@@ -661,7 +661,7 @@ virConnectPtr
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;
@@ -768,7 +768,7 @@ __virGetDomain(virConnectPtr conn, const char *name, const unsigned
char *uuid)
/*
* 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;
@@ -901,7 +901,7 @@ __virGetNetwork(virConnectPtr conn, const char *name, const unsigned
char *uuid)
/*
* 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;
diff --git a/src/iptables.c b/src/iptables.c
index ee92796..26794d2 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -215,7 +215,7 @@ iptRulesAppend(iptRules *rules,
{
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++]);
@@ -319,7 +319,7 @@ iptRulesNew(const char *table,
{
iptRules *rules;
- if (!(rules = (iptRules *)calloc(1, sizeof (iptRules))))
+ if (!(rules = calloc(1, sizeof (*rules))))
return NULL;
if (!(rules->table = strdup(table)))
@@ -400,7 +400,7 @@ iptablesAddRemoveChain(iptRules *rules, int action)
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;
@@ -458,7 +458,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg,
...)
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)))
@@ -549,7 +549,7 @@ iptablesContextNew(void)
{
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")))
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index 0502a1d..a886001 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -246,7 +246,7 @@ openvzAssignVMDef(virConnectPtr conn,
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;
@@ -298,7 +298,7 @@ static struct openvz_vm_def
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;
}
@@ -393,7 +393,7 @@ static struct openvz_vm_def
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;
}
@@ -465,7 +465,7 @@ static struct openvz_vm_def
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;
}
@@ -527,7 +527,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
}
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;
@@ -557,7 +557,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
(*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);
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 2d003af..2b87c88 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -918,7 +918,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
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;
}
@@ -1264,7 +1264,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(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;
@@ -1292,7 +1292,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(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;
@@ -1319,7 +1319,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(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;
@@ -1359,7 +1359,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
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;
@@ -1454,7 +1454,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
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;
@@ -1554,7 +1554,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
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;
@@ -1899,7 +1899,7 @@ qemudParseVMDeviceDef(virConnectPtr conn,
{
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 |
@@ -1981,7 +1981,7 @@ qemudAssignVMDef(virConnectPtr conn,
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;
}
@@ -2180,7 +2180,7 @@ static int qemudParseDhcpRangesXML(virConnectPtr conn,
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;
}
@@ -2272,7 +2272,7 @@ static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr
conn,
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;
}
@@ -2433,7 +2433,7 @@ qemudAssignNetworkDef(virConnectPtr conn,
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;
}
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 8c3e0af..f792eba 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -158,7 +158,7 @@ qemudStartup(void) {
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;
}
@@ -838,7 +838,7 @@ qemudBuildDnsmasqArgv(virConnectPtr conn,
(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 { \
diff --git a/src/remote_internal.c b/src/remote_internal.c
index 8174ba5..b6513fb 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -661,7 +661,7 @@ doRemoteOpen (virConnectPtr conn,
// 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;
@@ -724,7 +724,7 @@ doRemoteOpen (virConnectPtr conn,
// 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;
@@ -833,7 +833,7 @@ remoteOpen (virConnectPtr conn,
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;
@@ -2381,7 +2381,7 @@ remoteDomainSetSchedulerParameters (virDomainPtr domain,
/* 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");
@@ -2513,7 +2513,7 @@ remoteNetworkOpen (virConnectPtr conn,
* 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");
@@ -3088,7 +3088,7 @@ static int remoteAuthCredSASL2Vir(int vircred)
*/
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;
@@ -3125,7 +3125,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact,
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
; /* empty */
- *cred = calloc(ninteract, sizeof(virConnectCredential));
+ *cred = calloc(ninteract, sizeof(*cred));
if (!*cred)
return -1;
diff --git a/src/test.c b/src/test.c
index 0e85f73..825707c 100644
--- a/src/test.c
+++ b/src/test.c
@@ -592,7 +592,7 @@ static int testLoadNetworkFromFile(virConnectPtr conn,
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;
@@ -678,7 +678,7 @@ static int testOpenFromFile(virConnectPtr conn,
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;
diff --git a/src/xen_internal.c b/src/xen_internal.c
index 58ac677..20cf408 100644
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -1,7 +1,7 @@
/*
* 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
*
@@ -220,10 +220,10 @@ typedef struct xen_v2s4_availheap xen_v2s4_availheap;
#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 ? \
@@ -232,12 +232,12 @@ typedef struct xen_v2s4_availheap xen_v2s4_availheap;
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 ? \
@@ -1964,7 +1964,7 @@ xenHypervisorInit(void)
*/
hypervisor_version = 2;
- ipt = malloc(sizeof(virVcpuInfo));
+ ipt = malloc(sizeof(*ipt));
if (ipt == NULL){
#ifdef DEBUG
fprintf(stderr, "Memory allocation failed at xenHypervisorInit()\n");
diff --git a/src/xen_unified.c b/src/xen_unified.c
index 520424c..99f99ce 100644
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -168,10 +168,10 @@ xenDomainUsedCpus(virDomainPtr dom)
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));
diff --git a/src/xm_internal.c b/src/xm_internal.c
index 07abbb1..7d9eccd 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -231,7 +231,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char
*filename) {
/* 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);
}
@@ -252,7 +252,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char
*filename) {
virConfValuePtr value;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- value = malloc(sizeof(virConfValue));
+ value = malloc(sizeof(*value));
if (!value) {
return (-1);
}
@@ -401,7 +401,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
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;
}
@@ -1081,7 +1081,7 @@ int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory)
{
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return (-1);
value->type = VIR_CONF_LONG;
@@ -1123,7 +1123,7 @@ int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long
memory) {
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return (-1);
value->type = VIR_CONF_LONG;
@@ -1196,7 +1196,7 @@ int xenXMDomainSetVcpus(virDomainPtr domain, unsigned int vcpus) {
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(virConfValue))))
+ if (!(value = malloc(sizeof(*value))))
return (-1);
value->type = VIR_CONF_LONG;
@@ -1481,7 +1481,7 @@ static
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;
@@ -1496,7 +1496,7 @@ static
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;
@@ -2112,7 +2112,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
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;
}
@@ -2177,7 +2177,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
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;
@@ -2199,7 +2199,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
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;
}
@@ -2211,7 +2211,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
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;
@@ -2231,7 +2231,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
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;
}
@@ -2242,7 +2242,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
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");
@@ -2377,7 +2377,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char
*xml) {
goto error;
}
- if (!(entry = calloc(1, sizeof(xenXMConfCache)))) {
+ if (!(entry = calloc(1, sizeof(*entry)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
diff --git a/src/xml.c b/src/xml.c
index c75b0ce..c698889 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -322,7 +322,7 @@ virParseXenCpuTopology(virConnectPtr conn, virBufferPtr xml,
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;
@@ -433,7 +433,7 @@ virConvertCpuSet(virConnectPtr conn, const char *str, int maxcpu) {
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);
@@ -676,11 +676,11 @@ virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
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));
@@ -1636,7 +1636,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char
**name,
* 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) {
diff --git a/src/xmlrpc.c b/src/xmlrpc.c
index d65a7a9..b433ef5 100644
--- a/src/xmlrpc.c
+++ b/src/xmlrpc.c
@@ -153,6 +153,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
xmlRpcValuePtr ret = xmlRpcValueNew(XML_RPC_ARRAY);
xmlNodePtr cur;
int n_elements = 0;
+ xmlRpcValuePtr *elems;
if (!ret)
return NULL;
@@ -160,19 +161,20 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
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;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 95b4679..d4e39b2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -60,7 +60,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd)
{
len += strlen(*tmp) + 1;
tmp++;
}
- actualargv = malloc(sizeof(char)*len);
+ actualargv = malloc(sizeof(*actualargv)*len);
actualargv[0] = '\0';
tmp = argv;
len = 0;
--
1.5.3.7.1116.gae2a9