From 9be7c0d4d072bf1a8afce79fa2691a6610c4aeb6 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Fri, 14 Dec 2018 19:13:15 +0100 Subject: [PATCH 01/26] ceph plugin: use recommended style for calloc --- src/ceph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ceph.c b/src/ceph.c index c7fc576ad..c112af06e 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -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; } From ec6deefb347fad727b293995e8d3341a898c9812 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Fri, 14 Dec 2018 19:15:07 +0100 Subject: [PATCH 02/26] collectd-nagios: remove unneccesary casts --- src/collectd-nagios.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index 54be36aae..33580f9e4 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -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); From dd8d0c5985194889ca944b025fbd82f83351126e Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:08:36 +0100 Subject: [PATCH 03/26] barometer plugin: remove unneccesary cast --- src/barometer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/barometer.c b/src/barometer.c index a54d998a9..b6f2bc006 100644 --- a/src/barometer.c +++ b/src/barometer.c @@ -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", From 3548bea8b944215e162132c8ba6f1fa557941736 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:13:42 +0100 Subject: [PATCH 04/26] cpufreq plugin: fix minor style issue --- src/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpufreq.c b/src/cpufreq.c index a81cf4623..21b6429a1 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -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; From 6777942b404dced12f9e7b11031bb87252c13ca2 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:18:26 +0100 Subject: [PATCH 05/26] daemon/plugin.c: fix minor style issue --- src/daemon/plugin.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index c2017acad..bbf6144d1 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -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; } From a46085676d1c269add9a575f816f0514f96d8419 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:21:18 +0100 Subject: [PATCH 06/26] daemon/plugin.c: remove unneccesary casts --- src/daemon/plugin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index bbf6144d1..13d4891d6 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -627,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(pthread_t)); if (read_threads == NULL) { ERROR("plugin: start_read_threads: calloc failed."); return; @@ -816,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(pthread_t)); if (write_threads == NULL) { ERROR("plugin: start_write_threads: calloc failed."); return; From 3e795a5ff7f079b4d41d582bc97fb3332b727cc9 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:22:30 +0100 Subject: [PATCH 07/26] daemon/plugin.c: fix two more stylistic issues --- src/daemon/plugin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 13d4891d6..de04665ab 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -627,7 +627,7 @@ static void start_read_threads(size_t num) /* {{{ */ if (read_threads != NULL) return; - read_threads = calloc(num, sizeof(pthread_t)); + read_threads = calloc(num, sizeof(*read_threads)); if (read_threads == NULL) { ERROR("plugin: start_read_threads: calloc failed."); return; @@ -816,7 +816,7 @@ static void start_write_threads(size_t num) /* {{{ */ if (write_threads != NULL) return; - write_threads = calloc(num, sizeof(pthread_t)); + write_threads = calloc(num, sizeof(*write_threads)); if (write_threads == NULL) { ERROR("plugin: start_write_threads: calloc failed."); return; From f03ad26a9152f21c27a86103683b20ca116520bf Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:23:55 +0100 Subject: [PATCH 08/26] daemon/types_list.c: fix minor style issue --- src/daemon/types_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/daemon/types_list.c b/src/daemon/types_list.c index 1ccf10bcb..c3f590c15 100644 --- a/src/daemon/types_list.c +++ b/src/daemon/types_list.c @@ -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; From 136f4be1b628d66f94b27a7609a7774e86250b54 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:26:37 +0100 Subject: [PATCH 09/26] daemon/utils_cache.c: fix minor style issue --- src/daemon/utils_cache.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index e09b09994..cdb764224 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -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; From adc145315053e6d86bcdaf3738a7ee763c233e02 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:29:29 +0100 Subject: [PATCH 10/26] disk plugin: fix minor style issue --- src/disk.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/disk.c b/src/disk.c index 7edf44c78..7ceb95a61 100644 --- a/src/disk.c +++ b/src/disk.c @@ -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; From bbf34ecad8e0d8e50fd44cd3c4433b76385564ce Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:33:00 +0100 Subject: [PATCH 11/26] gmond plugin: fix minor style issues --- src/gmond.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gmond.c b/src/gmond.c index 291dfadb1..3312f96e8 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -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++) From 0441d713c248a778f090e5f105606c6bfff79ff9 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:36:36 +0100 Subject: [PATCH 12/26] intel_pmu plugin: fix some minor style issues --- src/intel_pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/intel_pmu.c b/src/intel_pmu.c index c9bbb50c0..ff92beede 100644 --- a/src/intel_pmu.c +++ b/src/intel_pmu.c @@ -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; From e1ec3684a913756f605fb1193dfcfe167415d49e Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:38:00 +0100 Subject: [PATCH 13/26] intel_rdt plugin: fix some minor style issues --- src/intel_rdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intel_rdt.c b/src/intel_rdt.c index 62ce9b806..df9c9c441 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -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(); From 201daa33f04ce0231ad911eb106afa6f407e991e Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:41:58 +0100 Subject: [PATCH 14/26] ipmi plugin: remove unneccesary cast --- src/ipmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipmi.c b/src/ipmi.c index fb99bad17..15909c2bc 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -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; From b6ec15f38e5b9326080dcc30932c6c0b92d8f6e5 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:42:59 +0100 Subject: [PATCH 15/26] java plugin: fix minor style issue --- src/java.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.c b/src/java.c index 3f4b3d1a9..0a5336a52 100644 --- a/src/java.c +++ b/src/java.c @@ -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); From 9fa5f66cfd8933bd2a02c118cc1215b350e76e97 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:44:40 +0100 Subject: [PATCH 16/26] libcollectdclient: fix minor style issue --- src/libcollectdclient/network_parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcollectdclient/network_parse.c b/src/libcollectdclient/network_parse.c index a8f6bd61c..73476fb7c 100644 --- a/src/libcollectdclient/network_parse.c +++ b/src/libcollectdclient/network_parse.c @@ -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; } From 21d673e2612bd4a1b2a2eeea8e025137326fd0c8 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:47:13 +0100 Subject: [PATCH 17/26] liboconfig: fix minor style issues --- src/liboconfig/oconfig.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index 0ffda3aa3..e05ced874 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -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); From 50339a2982d56ec9faad833d9a5e589329be52f9 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:50:18 +0100 Subject: [PATCH 18/26] oracle plugin: remove unneccesary cast --- src/oracle.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/oracle.c b/src/oracle.c index 1b17d9c39..1982aeefc 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -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; From bcc7d4720491aac9302cbe91629487d3ddedbc8f Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:53:24 +0100 Subject: [PATCH 19/26] ovs_stats plugin: fix some stylistic issues --- src/ovs_stats.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 1bf8e4e67..eca7329e8 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -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 { From 2cbbf2a166cba72b94e80eb55f029e1a4901823e Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 18:57:17 +0100 Subject: [PATCH 20/26] postgresql plugin: fix some stylistic issues --- src/postgresql.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/postgresql.c b/src/postgresql.c index ae887a17e..e62780622 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -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); From c494d2b91a1476275689c5ea6f1cf10f388221b9 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 19:01:41 +0100 Subject: [PATCH 21/26] snmp_agent plugin: fix minor nit --- src/snmp_agent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 1c7191ff8..2dfa6613d 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -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; From c34955d26af676052d1263978873ce6ff7539f81 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 19:07:56 +0100 Subject: [PATCH 22/26] utils_db_query.c: fix some minor style issues --- src/utils_db_query.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/utils_db_query.c b/src/utils_db_query.c index 0279a4717..81ad8b5bd 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -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); From fc7ccf8381117058e9c6bef155cc3fe6d6d9ac1c Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 19:17:16 +0100 Subject: [PATCH 23/26] utils_ovs.c: fix some minor stylistic issues --- src/utils_ovs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 4ca86aebe..6fe6fe764 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -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 */ From cfa076124a5897e7f5bcbf3c53343693bea3c371 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 19:20:43 +0100 Subject: [PATCH 24/26] utils_rrdcreate.c: fix minor style issue --- src/utils_rrdcreate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c index 8f92cfd33..7f1f23544 100644 --- a/src/utils_rrdcreate.c +++ b/src/utils_rrdcreate.c @@ -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); From f9bdd06f48889a85f3d0121dfe93339203c95da3 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 19:26:04 +0100 Subject: [PATCH 25/26] virt plugin: fix some minor style issues --- src/virt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/virt.c b/src/virt.c index f2acde073..a3f940514 100644 --- a/src/virt.c +++ b/src/virt.c @@ -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; } From 1fff3468b0f07d6200496018da6a99795db13337 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 15 Dec 2018 19:35:42 +0100 Subject: [PATCH 26/26] xencpu plugin: fix minor style issues --- src/xencpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/xencpu.c b/src/xencpu.c index 8cba476f7..8f177803a 100644 --- a/src/xencpu.c +++ b/src/xencpu.c @@ -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);