Merge pull request #3022 from rubenk/treewide-fix-some-style-issues

Treewide: fix some style issues
This commit is contained in:
Florian Forster
2018-12-16 08:33:39 +01:00
committed by GitHub
24 changed files with 76 additions and 82 deletions

View File

@@ -252,7 +252,7 @@ static averaging_t temperature_averaging;
* @return Zero when successful
*/
static int averaging_create(averaging_t *avg, int size) {
avg->ring_buffer = calloc((size_t)size, sizeof(*avg->ring_buffer));
avg->ring_buffer = calloc(size, sizeof(*avg->ring_buffer));
if (avg->ring_buffer == NULL) {
ERROR("barometer: averaging_create - ring buffer allocation of size %d "
"failed",

View File

@@ -1032,7 +1032,7 @@ static void cconn_close(struct cconn *io) {
static int cconn_process_data(struct cconn *io, yajl_struct *yajl,
yajl_handle hand) {
int ret;
struct values_tmp *vtmp = calloc(1, sizeof(struct values_tmp) * 1);
struct values_tmp *vtmp = calloc(1, sizeof(*vtmp));
if (!vtmp) {
return -ENOMEM;
}

View File

@@ -116,7 +116,7 @@ cn_strdup(const char *str) /* {{{ */
char *ret;
strsize = strlen(str) + 1;
ret = (char *)malloc(strsize);
ret = malloc(strsize);
if (ret != NULL)
memcpy(ret, str, strsize);
return ret;
@@ -130,13 +130,13 @@ static int filter_ds(size_t *values_num, double **values,
if (match_ds_g == NULL)
return RET_OKAY;
new_values = (gauge_t *)calloc(match_ds_num_g, sizeof(*new_values));
new_values = calloc(match_ds_num_g, sizeof(*new_values));
if (new_values == NULL) {
fprintf(stderr, "calloc failed: %s\n", strerror(errno));
return RET_UNKNOWN;
}
new_names = (char **)calloc(match_ds_num_g, sizeof(*new_names));
new_names = calloc(match_ds_num_g, sizeof(*new_names));
if (new_names == NULL) {
fprintf(stderr, "calloc failed: %s\n", strerror(errno));
free(new_values);

View File

@@ -37,7 +37,7 @@ struct cpu_data_t {
static bool report_p_stats = false;
static void cpufreq_stats_init(void) {
cpu_data = calloc(num_cpu, sizeof(struct cpu_data_t));
cpu_data = calloc(num_cpu, sizeof(*cpu_data));
if (cpu_data == NULL)
return;

View File

@@ -320,7 +320,6 @@ static void log_list_callbacks(llist_t **list, /* {{{ */
int i;
llentry_t *le;
int n;
char **keys;
n = llist_size(*list);
if (n == 0) {
@@ -328,11 +327,9 @@ static void log_list_callbacks(llist_t **list, /* {{{ */
return;
}
keys = calloc(n, sizeof(char *));
char **keys = calloc(n, sizeof(*keys));
if (keys == NULL) {
ERROR("%s: failed to allocate memory for list of callbacks", comment);
return;
}
@@ -630,7 +627,7 @@ static void start_read_threads(size_t num) /* {{{ */
if (read_threads != NULL)
return;
read_threads = (pthread_t *)calloc(num, sizeof(pthread_t));
read_threads = calloc(num, sizeof(*read_threads));
if (read_threads == NULL) {
ERROR("plugin: start_read_threads: calloc failed.");
return;
@@ -819,7 +816,7 @@ static void start_write_threads(size_t num) /* {{{ */
if (write_threads != NULL)
return;
write_threads = (pthread_t *)calloc(num, sizeof(pthread_t));
write_threads = calloc(num, sizeof(*write_threads));
if (write_threads == NULL) {
ERROR("plugin: start_write_threads: calloc failed.");
return;

View File

@@ -113,7 +113,7 @@ static void parse_line(char *buf) {
sstrncpy(ds->type, fields[0], sizeof(ds->type));
ds->ds_num = fields_num - 1;
ds->ds = (data_source_t *)calloc(ds->ds_num, sizeof(data_source_t));
ds->ds = calloc(ds->ds_num, sizeof(*ds->ds));
if (ds->ds == NULL) {
sfree(ds);
return;

View File

@@ -826,9 +826,7 @@ int uc_inc_hits(const data_set_t *ds, const value_list_t *vl, int step) {
* Iterator interface
*/
uc_iter_t *uc_get_iterator(void) {
uc_iter_t *iter;
iter = (uc_iter_t *)calloc(1, sizeof(*iter));
uc_iter_t *iter = calloc(1, sizeof(*iter));
if (iter == NULL)
return NULL;

View File

@@ -701,7 +701,7 @@ static int disk_read(void) {
break;
if (ds == NULL) {
if ((ds = (diskstats_t *)calloc(1, sizeof(diskstats_t))) == NULL)
if ((ds = calloc(1, sizeof(*ds))) == NULL)
continue;
if ((ds->name = strdup(disk_name)) == NULL) {
@@ -989,9 +989,8 @@ static int disk_read(void) {
}
if (numdisk != pnumdisk || stat_disk == NULL) {
if (stat_disk != NULL)
free(stat_disk);
stat_disk = (perfstat_disk_t *)calloc(numdisk, sizeof(perfstat_disk_t));
free(stat_disk);
stat_disk = calloc(numdisk, sizeof(*stat_disk));
}
pnumdisk = numdisk;

View File

@@ -413,7 +413,7 @@ static staging_entry_t *staging_entry_get(const char *host, /* {{{ */
sstrncpy(se->key, key, sizeof(se->key));
se->flags = 0;
se->vl.values = (value_t *)calloc(values_len, sizeof(*se->vl.values));
se->vl.values = calloc(values_len, sizeof(*se->vl.values));
if (se->vl.values == NULL) {
sfree(se);
return NULL;
@@ -743,8 +743,8 @@ static void *mc_receive_thread(void *arg) /* {{{ */
return (void *)-1;
}
mc_receive_sockets = (struct pollfd *)calloc(mc_receive_sockets_num,
sizeof(*mc_receive_sockets));
mc_receive_sockets =
calloc(mc_receive_sockets_num, sizeof(*mc_receive_sockets));
if (mc_receive_sockets == NULL) {
ERROR("gmond plugin: calloc failed.");
for (size_t i = 0; i < mc_receive_sockets_num; i++)

View File

@@ -267,7 +267,7 @@ static int pmu_config_hw_events(oconfig_item_t *ci) {
return -EINVAL;
}
g_ctx.hw_events = calloc(ci->values_num, sizeof(char *));
g_ctx.hw_events = calloc(ci->values_num, sizeof(*g_ctx.hw_events));
if (g_ctx.hw_events == NULL) {
ERROR(PMU_PLUGIN ": Failed to allocate hw events.");
return -ENOMEM;
@@ -446,7 +446,7 @@ static int pmu_add_events(struct eventlist *el, uint32_t type,
/* Allocate memory for event struct that contains array of efd structs
for all cores */
struct event *e =
calloc(sizeof(struct event) + sizeof(struct efd) * el->num_cpus, 1);
calloc(1, sizeof(struct event) + sizeof(struct efd) * el->num_cpus);
if (e == NULL) {
ERROR(PMU_PLUGIN ": Failed to allocate event structure");
return -ENOMEM;
@@ -482,7 +482,7 @@ static int pmu_add_hw_events(struct eventlist *el, char **e, size_t count) {
/* Allocate memory for event struct that contains array of efd structs
for all cores */
struct event *e =
calloc(sizeof(struct event) + sizeof(struct efd) * el->num_cpus, 1);
calloc(1, sizeof(struct event) + sizeof(struct efd) * el->num_cpus);
if (e == NULL) {
free(events);
return -ENOMEM;

View File

@@ -124,7 +124,7 @@ static void rdt_free_cgroups(void) {
static int rdt_default_cgroups(void) {
unsigned num_cores = g_rdt->pqos_cpu->num_cores;
g_rdt->cores.cgroups = calloc(num_cores, sizeof(*(g_rdt->cores.cgroups)));
g_rdt->cores.cgroups = calloc(num_cores, sizeof(*g_rdt->cores.cgroups));
if (g_rdt->cores.cgroups == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core groups array");
return -ENOMEM;
@@ -137,7 +137,7 @@ static int rdt_default_cgroups(void) {
char desc[DATA_MAX_NAME_LEN];
/* set core group info */
cgroup->cores = calloc(1, sizeof(*(cgroup->cores)));
cgroup->cores = calloc(1, sizeof(*cgroup->cores));
if (cgroup->cores == NULL) {
ERROR(RDT_PLUGIN ": Error allocating cores array");
rdt_free_cgroups();

View File

@@ -476,7 +476,7 @@ static int sensor_list_add(c_ipmi_instance_t *st, ipmi_sensor_t *sensor) {
return 0;
}
list_item = (c_ipmi_sensor_list_t *)calloc(1, sizeof(c_ipmi_sensor_list_t));
list_item = calloc(1, sizeof(*list_item));
if (list_item == NULL) {
pthread_mutex_unlock(&st->sensor_list_lock);
return -1;

View File

@@ -1057,7 +1057,7 @@ static int jtoc_values_array(JNIEnv *jvm_env, /* {{{ */
BAIL_OUT(-1);
}
values = (value_t *)calloc(values_num, sizeof(value_t));
values = calloc(values_num, sizeof(*values));
if (values == NULL) {
ERROR("java plugin: jtoc_values_array: calloc failed.");
BAIL_OUT(-1);

View File

@@ -303,8 +303,8 @@ static int parse_values(void *payload, size_t payload_size,
return EINVAL;
state->values_len = (size_t)n;
state->values = calloc(sizeof(*state->values), state->values_len);
state->values_types = calloc(sizeof(*state->values_types), state->values_len);
state->values = calloc(state->values_len, sizeof(*state->values));
state->values_types = calloc(state->values_len, sizeof(*state->values_types));
if ((state->values == NULL) || (state->values_types == NULL)) {
return ENOMEM;
}

View File

@@ -115,8 +115,7 @@ oconfig_item_t *oconfig_clone(const oconfig_item_t *ci_orig) {
if (ci_orig->values_num > 0) /* {{{ */
{
ci_copy->values = (oconfig_value_t *)calloc((size_t)ci_orig->values_num,
sizeof(*ci_copy->values));
ci_copy->values = calloc(ci_orig->values_num, sizeof(*ci_copy->values));
if (ci_copy->values == NULL) {
fprintf(stderr, "calloc failed.\n");
free(ci_copy->key);
@@ -144,8 +143,8 @@ oconfig_item_t *oconfig_clone(const oconfig_item_t *ci_orig) {
if (ci_orig->children_num > 0) /* {{{ */
{
ci_copy->children = (oconfig_item_t *)calloc((size_t)ci_orig->children_num,
sizeof(*ci_copy->children));
ci_copy->children =
calloc(ci_orig->children_num, sizeof(*ci_copy->children));
if (ci_copy->children == NULL) {
fprintf(stderr, "calloc failed.\n");
oconfig_free(ci_copy);

View File

@@ -247,9 +247,7 @@ static int o_config_add_database(oconfig_item_t *ci) /* {{{ */
} /* while (status == 0) */
while ((status == 0) && (db->queries_num > 0)) {
db->q_prep_areas = (udb_query_preparation_area_t **)calloc(
db->queries_num, sizeof(*db->q_prep_areas));
db->q_prep_areas = calloc(db->queries_num, sizeof(*db->q_prep_areas));
if (db->q_prep_areas == NULL) {
WARNING("oracle plugin: calloc failed");
status = -1;

View File

@@ -579,8 +579,8 @@ static interface_list_t *ovs_stats_new_port_interface(port_list_t *port,
interface_list_t *iface = ovs_stats_get_port_interface(port, uuid);
if (iface == NULL) {
iface = (interface_list_t *)calloc(1, sizeof(interface_list_t));
if (!iface) {
iface = calloc(1, sizeof(*iface));
if (iface == NULL) {
ERROR("%s: Error allocating interface", plugin_name);
return NULL;
}
@@ -602,8 +602,8 @@ static port_list_t *ovs_stats_new_port(bridge_list_t *bridge,
port_list_t *port = ovs_stats_get_port(uuid);
if (port == NULL) {
port = (port_list_t *)calloc(1, sizeof(port_list_t));
if (!port) {
port = calloc(1, sizeof(*port));
if (port == NULL) {
ERROR("%s: Error allocating port", plugin_name);
return NULL;
}
@@ -703,7 +703,7 @@ static int ovs_stats_update_bridge(yajl_val bridge) {
ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name));
if (br == NULL) {
br = calloc(1, sizeof(*br));
if (!br) {
if (br == NULL) {
ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br));
return -1;
}
@@ -1312,7 +1312,7 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) {
char const *br_name = child->values[j].value.string;
if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head,
br_name)) == NULL) {
if ((bridge = calloc(1, sizeof(bridge_list_t))) == NULL) {
if ((bridge = calloc(1, sizeof(*bridge))) == NULL) {
ERROR("%s: Error allocating memory for bridge", plugin_name);
goto cleanup_fail;
} else {

View File

@@ -511,14 +511,14 @@ static int c_psql_exec_query(c_psql_database_t *db, udb_query_t *q,
}
column_num = PQnfields(res);
column_names = (char **)calloc(column_num, sizeof(char *));
if (NULL == column_names) {
column_names = calloc(column_num, sizeof(*column_names));
if (column_names == NULL) {
log_err("calloc failed.");
BAIL_OUT(-1);
}
column_values = (char **)calloc(column_num, sizeof(char *));
if (NULL == column_values) {
column_values = calloc(column_num, sizeof(*column_values));
if (column_values == NULL) {
log_err("calloc failed.");
BAIL_OUT(-1);
}
@@ -976,9 +976,9 @@ static int config_query_param_add(udb_query_t *q, oconfig_item_t *ci) {
c_psql_param_t *tmp;
data = udb_query_get_user_data(q);
if (NULL == data) {
if (data == NULL) {
data = calloc(1, sizeof(*data));
if (NULL == data) {
if (data == NULL) {
log_err("Out of memory.");
return -1;
}
@@ -989,7 +989,7 @@ static int config_query_param_add(udb_query_t *q, oconfig_item_t *ci) {
}
tmp = realloc(data->params, (data->params_num + 1) * sizeof(*data->params));
if (NULL == tmp) {
if (tmp == NULL) {
log_err("Out of memory.");
return -1;
}
@@ -1176,9 +1176,7 @@ static int c_psql_config_database(oconfig_item_t *ci) {
}
if (db->queries_num > 0) {
db->q_prep_areas = (udb_query_preparation_area_t **)calloc(
db->queries_num, sizeof(*db->q_prep_areas));
db->q_prep_areas = calloc(db->queries_num, sizeof(*db->q_prep_areas));
if (db->q_prep_areas == NULL) {
log_err("Out of memory.");
c_psql_database_delete(db);

View File

@@ -2202,8 +2202,7 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) {
if (c_avl_get(g_agent->registered_oids, (void *)oid, NULL) == 0)
return OID_EXISTS;
else {
oid_t *new_oid = calloc(1, sizeof(*oid));
oid_t *new_oid = calloc(1, sizeof(*new_oid));
if (new_oid == NULL) {
ERROR(PLUGIN_NAME ": Could not allocate memory to register new OID");
return -ENOMEM;

View File

@@ -347,39 +347,42 @@ static int udb_result_prepare_result(udb_result_t const *r, /* {{{ */
* r->instances_buffer, r->values_buffer, and r->metadata_buffer {{{ */
if (r->instances_num > 0) {
prep_area->instances_pos =
(size_t *)calloc(r->instances_num, sizeof(size_t));
calloc(r->instances_num, sizeof(*prep_area->instances_pos));
if (prep_area->instances_pos == NULL) {
P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->instances_buffer =
(char **)calloc(r->instances_num, sizeof(char *));
calloc(r->instances_num, sizeof(*prep_area->instances_buffer));
if (prep_area->instances_buffer == NULL) {
P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
} /* if (r->instances_num > 0) */
prep_area->values_pos = (size_t *)calloc(r->values_num, sizeof(size_t));
prep_area->values_pos = calloc(r->values_num, sizeof(*prep_area->values_pos));
if (prep_area->values_pos == NULL) {
P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->values_buffer = (char **)calloc(r->values_num, sizeof(char *));
prep_area->values_buffer =
calloc(r->values_num, sizeof(*prep_area->values_buffer));
if (prep_area->values_buffer == NULL) {
P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->metadata_pos = (size_t *)calloc(r->metadata_num, sizeof(size_t));
prep_area->metadata_pos =
calloc(r->metadata_num, sizeof(*prep_area->metadata_pos));
if (prep_area->metadata_pos == NULL) {
P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);
}
prep_area->metadata_buffer = (char **)calloc(r->metadata_num, sizeof(char *));
prep_area->metadata_buffer =
calloc(r->metadata_num, sizeof(*prep_area->metadata_buffer));
if (prep_area->metadata_buffer == NULL) {
P_ERROR("udb_result_prepare_result: calloc failed.");
BAIL_OUT(-ENOMEM);

View File

@@ -609,9 +609,8 @@ static int ovs_db_json_data_process(ovs_db_t *pdb, const char *data,
/* Allocate JSON reader instance */
static ovs_json_reader_t *ovs_json_reader_alloc() {
ovs_json_reader_t *jreader = NULL;
if ((jreader = calloc(sizeof(ovs_json_reader_t), 1)) == NULL)
ovs_json_reader_t *jreader = calloc(1, sizeof(*jreader));
if (jreader == NULL)
return NULL;
return jreader;
@@ -720,13 +719,17 @@ static void ovs_db_reconnect(ovs_db_t *pdb) {
if (pdb->unix_path[0] != '\0') {
/* use UNIX socket instead of INET address */
node_info = pdb->unix_path;
result = calloc(1, sizeof(struct addrinfo));
struct sockaddr_un *sa_unix = calloc(1, sizeof(struct sockaddr_un));
if (result == NULL || sa_unix == NULL) {
sfree(result);
sfree(sa_unix);
struct sockaddr_un *sa_unix = calloc(1, sizeof(*sa_unix));
if (sa_unix == NULL)
return;
result = calloc(1, sizeof(*result));
if (result == NULL) {
free(sa_unix);
return;
}
result->ai_family = AF_UNIX;
result->ai_socktype = SOCK_STREAM;
result->ai_addrlen = sizeof(*sa_unix);
@@ -1121,7 +1124,7 @@ int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params,
if (cb) {
/* register result callback */
if ((new_cb = calloc(1, sizeof(ovs_callback_t))) == NULL)
if ((new_cb = calloc(1, sizeof(*new_cb))) == NULL)
goto yajl_gen_failure;
/* add new callback to front */
@@ -1179,7 +1182,7 @@ int ovs_db_table_cb_register(ovs_db_t *pdb, const char *tb_name,
return -1;
/* allocate new update callback */
if ((new_cb = calloc(1, sizeof(ovs_callback_t))) == NULL)
if ((new_cb = calloc(1, sizeof(*new_cb))) == NULL)
return -1;
/* init YAJL generator */

View File

@@ -111,7 +111,7 @@ static srrd_create_args_t *srrd_create_args_create(const char *filename,
return NULL;
}
args->argv = calloc((size_t)(argc + 1), sizeof(*args->argv));
args->argv = calloc(argc + 1, sizeof(*args->argv));
if (args->argv == NULL) {
P_ERROR("srrd_create_args_create: calloc failed.");
srrd_create_args_destroy(args);

View File

@@ -1432,7 +1432,7 @@ static int lv_domain_block_info(virDomainPtr dom, const char *path,
return -1;
}
virTypedParameterPtr params = calloc((size_t)nparams, sizeof(*params));
virTypedParameterPtr params = calloc(nparams, sizeof(*params));
if (params == NULL) {
ERROR("virt plugin: alloc(%i) for block=%s parameters failed.", nparams,
path);
@@ -1502,7 +1502,7 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) {
int max_cpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
int cpu_map_len = VIR_CPU_MAPLEN(max_cpus);
virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(vinfo[0]));
virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(*vinfo));
if (vinfo == NULL) {
ERROR(PLUGIN_NAME " plugin: calloc failed.");
return -1;
@@ -1544,7 +1544,7 @@ static int get_pcpu_stats(virDomainPtr dom) {
return -1;
}
virTypedParameterPtr param = calloc(nparams, sizeof(virTypedParameter));
virTypedParameterPtr param = calloc(nparams, sizeof(*param));
if (param == NULL) {
ERROR(PLUGIN_NAME " plugin: alloc(%i) for cpu parameters failed.", nparams);
return -1;
@@ -1627,9 +1627,9 @@ static int get_domain_state_notify(virDomainPtr domain) {
static int get_memory_stats(virDomainPtr domain) {
virDomainMemoryStatPtr minfo =
calloc(VIR_DOMAIN_MEMORY_STAT_NR, sizeof(virDomainMemoryStatStruct));
calloc(VIR_DOMAIN_MEMORY_STAT_NR, sizeof(*minfo));
if (minfo == NULL) {
ERROR("virt plugin: malloc failed.");
ERROR("virt plugin: calloc failed.");
return -1;
}

View File

@@ -56,7 +56,7 @@ static int xencpu_init(void) {
xc_physinfo_t *physinfo;
physinfo = calloc(1, sizeof(xc_physinfo_t));
physinfo = calloc(1, sizeof(*physinfo));
if (physinfo == NULL) {
ERROR("xencpu plugin: calloc() for physinfo failed.");
xc_interface_close(xc_handle);
@@ -75,14 +75,14 @@ static int xencpu_init(void) {
INFO("xencpu plugin: Found %" PRIu32 " processors.", num_cpus);
cpu_info = calloc(num_cpus, sizeof(xc_cpuinfo_t));
cpu_info = calloc(num_cpus, sizeof(*cpu_info));
if (cpu_info == NULL) {
ERROR("xencpu plugin: calloc() for num_cpus failed.");
xc_interface_close(xc_handle);
return ENOMEM;
}
cpu_states = calloc(num_cpus, sizeof(value_to_rate_state_t));
cpu_states = calloc(num_cpus, sizeof(*cpu_states));
if (cpu_states == NULL) {
ERROR("xencpu plugin: calloc() for cpu_states failed.");
xc_interface_close(xc_handle);