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_.
This commit is contained in:
Jim Meyering
2007-12-11 21:57:29 +00:00
parent 5a190594f4
commit 49230350fa
22 changed files with 150 additions and 116 deletions

View File

@@ -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++) {

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;
}