From: Ruben Kerkhof Date: Sat, 30 Jul 2016 10:23:11 +0000 (+0200) Subject: treewide: replace memset to 0 with initializers X-Git-Tag: collectd-5.6.0~132^2~10 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=69b8a9a1af204685dfdfaf1279a0f2928e0bbb32;p=collectd.git treewide: replace memset to 0 with initializers --- diff --git a/src/aggregation.c b/src/aggregation.c index c4c1627a..84df5485 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -337,7 +337,7 @@ static int agg_instance_read_func (agg_instance_t *inst, /* {{{ */ char const *func, gauge_t rate, rate_to_value_state_t *state, value_list_t *vl, char const *pi_prefix, cdtime_t t) { - value_t v; + value_t v = { 0 } ; int status; if (pi_prefix[0] != 0) @@ -346,7 +346,6 @@ static int agg_instance_read_func (agg_instance_t *inst, /* {{{ */ else sstrncpy (vl->plugin_instance, func, sizeof (vl->plugin_instance)); - memset (&v, 0, sizeof (v)); status = rate_to_value (&v, rate, state, inst->ds_type, t); if (status != 0) { diff --git a/src/amqp.c b/src/amqp.c index 99dca901..71e38a47 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -763,14 +763,13 @@ static int camqp_subscribe_init (camqp_config_t *conf) /* {{{ */ static int camqp_write_locked (camqp_config_t *conf, /* {{{ */ const char *buffer, const char *routing_key) { - amqp_basic_properties_t props; + amqp_basic_properties_t props = { 0 }; int status; status = camqp_connect (conf); if (status != 0) return (status); - memset (&props, 0, sizeof (props)); props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG | AMQP_BASIC_APP_ID_FLAG; @@ -808,14 +807,12 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */ { camqp_config_t *conf = user_data->data; char routing_key[6 * DATA_MAX_NAME_LEN]; - char buffer[8192]; + char buffer[8192] = { 0 }; int status; if ((ds == NULL) || (vl == NULL) || (conf == NULL)) return (EINVAL); - memset (buffer, 0, sizeof (buffer)); - if (conf->routing_key != NULL) { sstrncpy (routing_key, conf->routing_key, sizeof (routing_key)); diff --git a/src/apache.c b/src/apache.c index 40d0efe2..8c24a703 100644 --- a/src/apache.c +++ b/src/apache.c @@ -240,14 +240,12 @@ static int config_add (oconfig_item_t *ci) if (status == 0) { - user_data_t ud; - char callback_name[3*DATA_MAX_NAME_LEN]; + user_data_t ud = { 0 }; + char callback_name[3*DATA_MAX_NAME_LEN] = { 0 }; - memset (&ud, 0, sizeof (ud)); ud.data = st; ud.free_func = apache_free; - memset (callback_name, 0, sizeof (callback_name)); ssnprintf (callback_name, sizeof (callback_name), "apache/%s/%s", (st->host != NULL) ? st->host : hostname_g, diff --git a/src/apcups.c b/src/apcups.c index 9f7476bf..84249339 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -115,12 +115,10 @@ static int net_open (char const *node, char const *service) { int sd; int status; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_return; struct addrinfo *ai_list; - /* Resolve name */ - memset (&ai_hints, 0, sizeof (ai_hints)); /* TODO: Change this to `AF_UNSPEC' if apcupsd can handle IPv6 */ ai_hints.ai_family = AF_INET; ai_hints.ai_socktype = SOCK_STREAM; diff --git a/src/ascent.c b/src/ascent.c index 9124c26d..a947bce9 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -365,9 +365,9 @@ static int ascent_xml_sessions_plr (xmlDoc *doc, xmlNode *node, /* {{{ */ static int ascent_xml_sessions (xmlDoc *doc, xmlNode *node) /* {{{ */ { xmlNode *child; - player_stats_t ps; - - memset (&ps, 0, sizeof (ps)); + player_stats_t ps = { + .level_sum = 0 + }; for (child = node->xmlChildrenNode; child != NULL; child = child->next) { diff --git a/src/bind.c b/src/bind.c index 7d262086..d46d4967 100644 --- a/src/bind.c +++ b/src/bind.c @@ -417,7 +417,7 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */ xmlNode *node; char *str_ptr; char *tmp; - struct tm tm; + struct tm tm = { 0 }; xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -458,7 +458,6 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */ return (-1); } - memset (&tm, 0, sizeof(tm)); tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm); xmlFree(str_ptr); if (tmp == NULL) diff --git a/src/ceph.c b/src/ceph.c index 04a39743..c34d209e 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -267,7 +267,7 @@ ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len) { yajl_struct *state = (yajl_struct*) ctx; char buffer[number_len+1]; - char key[2 * DATA_MAX_NAME_LEN]; + char key[2 * DATA_MAX_NAME_LEN] = { 0 }; _Bool latency_type = 0; size_t i; int status; @@ -275,7 +275,6 @@ ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len) memcpy(buffer, number_val, number_len); buffer[sizeof(buffer) - 1] = 0; - memset (key, 0, sizeof (key)); for (i = 0; i < state->depth; i++) { if (state->stack[i] == NULL) @@ -592,8 +591,7 @@ static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name, int pc_type) { uint32_t type; - char ds_name[DATA_MAX_NAME_LEN]; - memset(ds_name, 0, sizeof(ds_name)); + char ds_name[DATA_MAX_NAME_LEN] = { 0 }; if(convert_special_metrics) { @@ -685,9 +683,8 @@ static int cc_handle_bool(struct oconfig_item_s *item, int *dest) static int cc_add_daemon_config(oconfig_item_t *ci) { int ret, i; - struct ceph_daemon *nd, cd; + struct ceph_daemon *nd, cd = { 0 }; struct ceph_daemon **tmp; - memset(&cd, 0, sizeof(struct ceph_daemon)); if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -982,8 +979,7 @@ static int node_handler_fetch_data(void *arg, const char *val, const char *key) uint32_t type = DSET_TYPE_UNFOUND; int index = vtmp->index; - char ds_name[DATA_MAX_NAME_LEN]; - memset(ds_name, 0, sizeof(ds_name)); + char ds_name[DATA_MAX_NAME_LEN] = { 0 }; if (parse_keys (ds_name, sizeof (ds_name), key)) { @@ -1086,7 +1082,7 @@ static int node_handler_fetch_data(void *arg, const char *val, const char *key) static int cconn_connect(struct cconn *io) { - struct sockaddr_un address; + struct sockaddr_un address = { 0 }; int flags, fd, err; if(io->state != CSTATE_UNCONNECTED) { @@ -1101,7 +1097,6 @@ static int cconn_connect(struct cconn *io) "failed: error %d", err); return err; } - memset(&address, 0, sizeof(struct sockaddr_un)); address.sun_family = AF_UNIX; snprintf(address.sun_path, sizeof(address.sun_path), "%s", io->d->asok_path); diff --git a/src/chrony.c b/src/chrony.c index 012fd9a9..4a09753f 100644 --- a/src/chrony.c +++ b/src/chrony.c @@ -306,11 +306,10 @@ static int connect_client(const char *p_hostname, const char *p_service, int p_family, int p_socktype) { - struct addrinfo hints, *res = NULL, *ressave = NULL; + struct addrinfo hints = { 0 }; + struct addrinfo *res = NULL, *ressave = NULL; int n, sockfd; - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = p_family; hints.ai_socktype = p_socktype; @@ -852,8 +851,7 @@ chrony_request_daemon_stats(void) } #if COLLECT_DEBUG { - char src_addr[IPV6_STR_MAX_SIZE]; - memset(src_addr, 0, sizeof(src_addr)); + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; niptoha(&chrony_resp.body.tracking.addr, src_addr, sizeof(src_addr)); DEBUG(PLUGIN_NAME ": Daemon stat: .addr = %s, .ref_id= %u, .stratum = %u, .leap_status = %u, .ref_time = %u:%u:%u, .current_correction = %f, .last_offset = %f, .rms_offset = %f, .freq_ppm = %f, .skew_ppm = %f, .root_delay = %f, .root_dispersion = %f, .last_update_interval = %f", src_addr, ntohs(chrony_resp.body.tracking.f_ref_id), ntohs(chrony_resp.body.tracking.f_stratum), @@ -937,8 +935,7 @@ chrony_request_source_data(int p_src_idx, int *p_is_reachable) tChrony_Request chrony_req; tChrony_Response chrony_resp; - char src_addr[IPV6_STR_MAX_SIZE]; - memset(src_addr, 0, sizeof(src_addr)); + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; chrony_init_req(&chrony_req); chrony_req.body.source_data.f_index = htonl(p_src_idx); @@ -997,8 +994,7 @@ chrony_request_source_stats(int p_src_idx, const int *p_is_reachable) tChrony_Response chrony_resp; double skew_ppm, frequency_error, time_offset; - char src_addr[IPV6_STR_MAX_SIZE]; - memset(src_addr, 0, sizeof(src_addr)); + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; if (*p_is_reachable == 0) { diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index dd90737f..c1a85156 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -590,7 +590,6 @@ static int do_check (lcc_connection_t *connection) hostname_g, value_string_g); ident_str[sizeof (ident_str) - 1] = 0; - memset (&ident, 0, sizeof (ident)); status = lcc_string_to_identifier (connection, &ident, ident_str); if (status != 0) { diff --git a/src/collectdctl.c b/src/collectdctl.c index 18b39173..8ca0559d 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -194,7 +194,6 @@ static int getval (lcc_connection_t *c, int argc, char **argv) return (-1); } - memset (&ident, 0, sizeof (ident)); status = parse_identifier (c, argv[1], &ident); if (status != 0) return (status); diff --git a/src/conntrack.c b/src/conntrack.c index 486b0011..123ff543 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -74,14 +74,13 @@ static int conntrack_read (void) { value_t conntrack, conntrack_max, conntrack_pct; FILE *fh; - char buffer[64]; + char buffer[64] = { 0 }; size_t buffer_len; fh = fopen (old_files?CONNTRACK_FILE_OLD:CONNTRACK_FILE, "r"); if (fh == NULL) return (-1); - memset (buffer, 0, sizeof (buffer)); if (fgets (buffer, sizeof (buffer), fh) == NULL) { fclose (fh); diff --git a/src/csv.c b/src/csv.c index 7b513e73..0cb9bc1a 100644 --- a/src/csv.c +++ b/src/csv.c @@ -269,7 +269,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl, char values[4096]; FILE *csv; int csv_fd; - struct flock fl; + struct flock fl = { 0 }; int status; if (0 != strcmp (ds->type, vl->type)) { @@ -342,9 +342,6 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl, } csv_fd = fileno (csv); - memset (&fl, '\0', sizeof (fl)); - fl.l_start = 0; - fl.l_len = 0; /* till end of file */ fl.l_pid = getpid (); fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; diff --git a/src/curl_json.c b/src/curl_json.c index 55db3877..2dac7479 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -760,7 +760,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ /* If all went well, register this database for reading */ if (status == 0) { - user_data_t ud; + user_data_t ud = { 0 }; char *cb_name; if (db->instance == NULL) @@ -769,7 +769,6 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ DEBUG ("curl_json plugin: Registering new read callback: %s", db->instance); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = cj_free; diff --git a/src/curl_xml.c b/src/curl_xml.c index e0e4a62f..05d75c67 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -1024,7 +1024,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ /* If all went well, register this database for reading */ if (status == 0) { - user_data_t ud; + user_data_t ud = { 0 }; char *cb_name; if (db->instance == NULL) @@ -1033,7 +1033,6 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ DEBUG ("curl_xml plugin: Registering new read callback: %s", db->instance); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = cx_free; diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index 2fce643d..84052088 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -97,7 +97,7 @@ static int init_hostname (void) { const char *str; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list; struct addrinfo *ai_ptr; int status; @@ -120,7 +120,6 @@ static int init_hostname (void) if (IS_FALSE (str)) return (0); - memset (&ai_hints, '\0', sizeof (ai_hints)); ai_hints.ai_flags = AI_CANONNAME; status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list); @@ -441,7 +440,7 @@ static int notify_systemd (void) { int fd; const char *notifysocket; - struct sockaddr_un su; + struct sockaddr_un su = { 0 }; size_t su_size; char buffer[] = "READY=1\n"; @@ -471,7 +470,6 @@ static int notify_systemd (void) return 0; } - memset (&su, 0, sizeof (su)); su.sun_family = AF_UNIX; if (notifysocket[0] != '@') { @@ -509,16 +507,11 @@ static int notify_systemd (void) int main (int argc, char **argv) { - struct sigaction sig_int_action; - struct sigaction sig_term_action; - struct sigaction sig_usr1_action; - struct sigaction sig_pipe_action; const char *configfile = CONFIGFILE; int test_config = 0; int test_readall = 0; const char *basedir; #if COLLECT_DAEMON - struct sigaction sig_chld_action; pid_t pid; int daemonize = 1; #endif @@ -618,8 +611,10 @@ int main (int argc, char **argv) /* * fork off child */ - memset (&sig_chld_action, '\0', sizeof (sig_chld_action)); - sig_chld_action.sa_handler = SIG_IGN; + struct sigaction sig_chld_action = { + .sa_handler = SIG_IGN + }; + sigaction (SIGCHLD, &sig_chld_action, NULL); /* @@ -685,15 +680,19 @@ int main (int argc, char **argv) } /* if (daemonize) */ #endif /* COLLECT_DAEMON */ - memset (&sig_pipe_action, '\0', sizeof (sig_pipe_action)); - sig_pipe_action.sa_handler = SIG_IGN; + struct sigaction sig_pipe_action = { + .sa_handler = SIG_IGN + }; + sigaction (SIGPIPE, &sig_pipe_action, NULL); /* * install signal handlers */ - memset (&sig_int_action, '\0', sizeof (sig_int_action)); - sig_int_action.sa_handler = sig_int_handler; + struct sigaction sig_int_action = { + .sa_handler = sig_int_handler + }; + if (0 != sigaction (SIGINT, &sig_int_action, NULL)) { char errbuf[1024]; ERROR ("Error: Failed to install a signal handler for signal INT: %s", @@ -701,8 +700,10 @@ int main (int argc, char **argv) return (1); } - memset (&sig_term_action, '\0', sizeof (sig_term_action)); - sig_term_action.sa_handler = sig_term_handler; + struct sigaction sig_term_action = { + .sa_handler = sig_term_handler + }; + if (0 != sigaction (SIGTERM, &sig_term_action, NULL)) { char errbuf[1024]; ERROR ("Error: Failed to install a signal handler for signal TERM: %s", @@ -710,8 +711,10 @@ int main (int argc, char **argv) return (1); } - memset (&sig_usr1_action, '\0', sizeof (sig_usr1_action)); - sig_usr1_action.sa_handler = sig_usr1_handler; + struct sigaction sig_usr1_action = { + .sa_handler = sig_usr1_handler + }; + if (0 != sigaction (SIGUSR1, &sig_usr1_action, NULL)) { char errbuf[1024]; ERROR ("Error: Failed to install a signal handler for signal USR1: %s", diff --git a/src/daemon/common.c b/src/daemon/common.c index f9b1433b..9da47755 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -1518,7 +1518,7 @@ int service_name_to_port_number (const char *service_name) { struct addrinfo *ai_list; struct addrinfo *ai_ptr; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; int status; int service_number; @@ -1526,7 +1526,6 @@ int service_name_to_port_number (const char *service_name) return (-1); ai_list = NULL; - memset (&ai_hints, 0, sizeof (ai_hints)); ai_hints.ai_family = AF_UNSPEC; status = getaddrinfo (/* node = */ NULL, service_name, diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index b9860bd9..0654ad7e 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -273,7 +273,7 @@ static int dispatch_loadplugin (oconfig_item_t *ci) int i; const char *name; unsigned int flags = 0; - plugin_ctx_t ctx; + plugin_ctx_t ctx = { 0 }; plugin_ctx_t old_ctx; int ret_val; @@ -289,7 +289,6 @@ static int dispatch_loadplugin (oconfig_item_t *ci) name = "virt"; /* default to the global interval set before loading this plugin */ - memset (&ctx, 0, sizeof (ctx)); ctx.interval = cf_get_default_interval (); ctx.flush_interval = 0; ctx.flush_timeout = 0; @@ -406,12 +405,11 @@ static int dispatch_block_plugin (oconfig_item_t *ci) if (IS_TRUE (global_option_get ("AutoLoadPlugin"))) { - plugin_ctx_t ctx; + plugin_ctx_t ctx = { 0 }; plugin_ctx_t old_ctx; int status; /* default to the global interval set before loading this plugin */ - memset (&ctx, 0, sizeof (ctx)); ctx.interval = cf_get_default_interval (); old_ctx = plugin_set_ctx (ctx); diff --git a/src/daemon/filter_chain.c b/src/daemon/filter_chain.c index a622af96..c10525de 100644 --- a/src/daemon/filter_chain.c +++ b/src/daemon/filter_chain.c @@ -773,12 +773,11 @@ static int fc_bit_write_invoke (const data_set_t *ds, /* {{{ */ static int fc_init_once (void) /* {{{ */ { static int done = 0; - target_proc_t tproc; + target_proc_t tproc = { 0 }; if (done != 0) return (0); - memset (&tproc, 0, sizeof (tproc)); tproc.create = fc_bit_jump_create; tproc.destroy = fc_bit_jump_destroy; tproc.invoke = fc_bit_jump_invoke; diff --git a/src/daemon/utils_match.c b/src/daemon/utils_match.c index cf87b6b7..b4cd5171 100644 --- a/src/daemon/utils_match.c +++ b/src/daemon/utils_match.c @@ -321,7 +321,7 @@ int match_apply (cu_match_t *obj, const char *str) { int status; regmatch_t re_match[32]; - char *matches[32]; + char *matches[32] = { 0 }; size_t matches_num; size_t i; @@ -347,7 +347,6 @@ int match_apply (cu_match_t *obj, const char *str) if (status != 0) return (0); - memset (matches, '\0', sizeof (matches)); for (matches_num = 0; matches_num < STATIC_ARRAY_SIZE (matches); matches_num++) { if ((re_match[matches_num].rm_so < 0) diff --git a/src/daemon/utils_tail.c b/src/daemon/utils_tail.c index 0b0a8fb4..a6fb6005 100644 --- a/src/daemon/utils_tail.c +++ b/src/daemon/utils_tail.c @@ -45,10 +45,9 @@ static int cu_tail_reopen (cu_tail_t *obj) { int seek_end = 0; FILE *fh; - struct stat stat_buf; + struct stat stat_buf = { 0 }; int status; - memset (&stat_buf, 0, sizeof (stat_buf)); status = stat (obj->file, &stat_buf); if (status != 0) { diff --git a/src/dbi.c b/src/dbi.c index 273cce8e..d5a6c603 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -395,14 +395,13 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ } else { - user_data_t ud; + user_data_t ud = { 0 }; char *name = NULL; databases = temp; databases[databases_num] = db; databases_num++; - memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = NULL; name = ssnprintf_alloc("dbi:%s", db->name); diff --git a/src/dns.c b/src/dns.c index 2c3a9043..5930dc50 100644 --- a/src/dns.c +++ b/src/dns.c @@ -210,7 +210,7 @@ static int dns_run_pcap_loop (void) { pcap_t *pcap_obj; char pcap_error[PCAP_ERRBUF_SIZE]; - struct bpf_program fp; + struct bpf_program fp = { 0 }; int status; @@ -237,7 +237,6 @@ static int dns_run_pcap_loop (void) return (PCAP_ERROR); } - memset (&fp, 0, sizeof (fp)); status = pcap_compile (pcap_obj, &fp, "udp port 53", 1, 0); if (status < 0) { diff --git a/src/ethstat.c b/src/ethstat.c index 959737a3..b30f614e 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -216,8 +216,6 @@ static void ethstat_submit_value (const char *device, static int ethstat_read_interface (char *device) { int fd; - struct ifreq req; - struct ethtool_drvinfo drvinfo; struct ethtool_gstrings *strings; struct ethtool_stats *stats; size_t n_stats; @@ -226,9 +224,6 @@ static int ethstat_read_interface (char *device) size_t i; int status; - memset (&req, 0, sizeof (req)); - sstrncpy(req.ifr_name, device, sizeof (req.ifr_name)); - fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0); if (fd < 0) { @@ -238,9 +233,16 @@ static int ethstat_read_interface (char *device) return 1; } - memset (&drvinfo, 0, sizeof (drvinfo)); - drvinfo.cmd = ETHTOOL_GDRVINFO; - req.ifr_data = (void *) &drvinfo; + struct ethtool_drvinfo drvinfo = { + .cmd = ETHTOOL_GDRVINFO + }; + + struct ifreq req = { + .ifr_data = (void *) &drvinfo + }; + + sstrncpy(req.ifr_name, device, sizeof (req.ifr_name)); + status = ioctl (fd, SIOCETHTOOL, &req); if (status < 0) { diff --git a/src/exec.c b/src/exec.c index cdaf79a0..71a49181 100644 --- a/src/exec.c +++ b/src/exec.c @@ -346,7 +346,6 @@ static void reset_signal_mask (void) /* {{{ */ { sigset_t ss; - memset (&ss, 0, sizeof (ss)); sigemptyset (&ss); sigprocmask (SIG_SETMASK, &ss, /* old mask = */ NULL); } /* }}} void reset_signal_mask */ @@ -804,10 +803,10 @@ static void *exec_notification_one (void *arg) /* {{{ */ static int exec_init (void) /* {{{ */ { - struct sigaction sa; + struct sigaction sa = { + .sa_handler = sigchld_handler + }; - memset (&sa, '\0', sizeof (sa)); - sa.sa_handler = sigchld_handler; sigaction (SIGCHLD, &sa, NULL); return (0); diff --git a/src/gmond.c b/src/gmond.c index 728162ec..47158c97 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -211,7 +211,7 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ size_t *ret_sockets_num, const char *node, const char *service, int listen) { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list; struct addrinfo *ai_ptr; int ai_return; @@ -224,8 +224,6 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ if (*ret_sockets != NULL) return (EINVAL); - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_PASSIVE ai_hints.ai_flags |= AI_PASSIVE; #endif @@ -308,7 +306,6 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ if (ai_ptr->ai_family == AF_INET) { struct sockaddr_in *addr; - struct ip_mreq mreq; int loop; addr = (struct sockaddr_in *) ai_ptr->ai_addr; @@ -329,9 +326,10 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ sstrerror (errno, errbuf, sizeof (errbuf))); } - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_interface.s_addr = htonl (INADDR_ANY); + struct ip_mreq mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_interface.s_addr = htonl (INADDR_ANY) + }; status = setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *) &mreq, sizeof (mreq)); @@ -345,7 +343,6 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ else if (ai_ptr->ai_family == AF_INET6) { struct sockaddr_in6 *addr; - struct ipv6_mreq mreq; int loop; addr = (struct sockaddr_in6 *) ai_ptr->ai_addr; @@ -366,10 +363,12 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ sstrerror (errno, errbuf, sizeof (errbuf))); } - memset (&mreq, 0, sizeof (mreq)); + struct ipv6_mreq mreq = { + .ipv6mr_interface = 0 /* any */ + }; + memcpy (&mreq.ipv6mr_multiaddr, &addr->sin6_addr, sizeof (addr->sin6_addr)); - mreq.ipv6mr_interface = 0; /* any */ status = setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (void *) &mreq, sizeof (mreq)); if (status != 0) @@ -398,14 +397,12 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ static int request_meta_data (const char *host, const char *name) /* {{{ */ { - Ganglia_metadata_msg msg; - char buffer[BUFF_SIZE]; + Ganglia_metadata_msg msg = { 0 }; + char buffer[BUFF_SIZE] = { 0 }; unsigned int buffer_size; XDR xdr; size_t i; - memset (&msg, 0, sizeof (msg)); - msg.id = gmetadata_request; msg.Ganglia_metadata_msg_u.grequest.metric_id.host = strdup (host); msg.Ganglia_metadata_msg_u.grequest.metric_id.name = strdup (name); @@ -418,7 +415,6 @@ static int request_meta_data (const char *host, const char *name) /* {{{ */ return (-1); } - memset (buffer, 0, sizeof (buffer)); xdrmem_create (&xdr, buffer, sizeof (buffer), XDR_ENCODE); if (!xdr_Ganglia_metadata_msg (&xdr, &msg)) @@ -782,9 +778,8 @@ static int mc_handle_metric (void *buffer, size_t buffer_size) /* {{{ */ case gmetric_float: case gmetric_double: { - Ganglia_value_msg msg; + Ganglia_value_msg msg = { 0 }; - memset (&msg, 0, sizeof (msg)); if (xdr_Ganglia_value_msg (&xdr, &msg)) mc_handle_value_msg (&msg); break; @@ -793,8 +788,7 @@ static int mc_handle_metric (void *buffer, size_t buffer_size) /* {{{ */ case gmetadata_full: case gmetadata_request: { - Ganglia_metadata_msg msg; - memset (&msg, 0, sizeof (msg)); + Ganglia_metadata_msg msg = { 0 }; if (xdr_Ganglia_metadata_msg (&xdr, &msg)) mc_handle_metadata_msg (&msg); break; diff --git a/src/hddtemp.c b/src/hddtemp.c index 3de18fd9..c32aa358 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -88,12 +88,10 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) const char *host; const char *port; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list, *ai_ptr; int ai_return; - memset (&ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif diff --git a/src/ipmi.c b/src/ipmi.c index c3aa5587..8b957e50 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -80,9 +80,7 @@ static int c_ipmi_nofiy_notpresent = 0; */ static void c_ipmi_error (const char *func, int status) { - char errbuf[4096]; - - memset (errbuf, 0, sizeof (errbuf)); + char errbuf[4096] = { 0 }; if (IPMI_IS_OS_ERR (status)) { @@ -234,7 +232,7 @@ static int sensor_list_add (ipmi_sensor_t *sensor) c_ipmi_sensor_list_t *list_item; c_ipmi_sensor_list_t *list_prev; - char buffer[DATA_MAX_NAME_LEN]; + char buffer[DATA_MAX_NAME_LEN] = { 0 }; const char *entity_id_string; char sensor_name[DATA_MAX_NAME_LEN]; char *sensor_name_ptr; @@ -244,7 +242,6 @@ static int sensor_list_add (ipmi_sensor_t *sensor) sensor_id = ipmi_sensor_convert_to_id (sensor); - memset (buffer, 0, sizeof (buffer)); ipmi_sensor_get_name (sensor, buffer, sizeof (buffer)); buffer[sizeof (buffer) - 1] = 0; @@ -550,7 +547,7 @@ static void domain_connection_change_handler (ipmi_domain_t *domain, static int thread_init (os_handler_t **ret_os_handler) { os_handler_t *os_handler; - ipmi_open_option_t open_option[1]; + ipmi_open_option_t open_option[1] = { 0 }; ipmi_con_t *smi_connection = NULL; ipmi_domain_id_t domain_id; int status; @@ -574,7 +571,6 @@ static int thread_init (os_handler_t **ret_os_handler) return (-1); } - memset (open_option, 0, sizeof (open_option)); open_option[0].option = IPMI_OPEN_OPTION_ALL; open_option[0].ival = 1; diff --git a/src/iptables.c b/src/iptables.c index 0103725f..20dce658 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -111,7 +111,8 @@ static int iptables_config (const char *key, const char *value) else return (1); - ip_chain_t temp, *final, **list; + ip_chain_t temp = { 0 }; + ip_chain_t *final, **list; char *table; int table_len; char *chain; @@ -121,8 +122,6 @@ static int iptables_config (const char *key, const char *value) char *fields[4]; int fields_num; - memset (&temp, 0, sizeof (temp)); - value_copy = strdup (value); if (value_copy == NULL) { diff --git a/src/java.c b/src/java.c index 01dc1b8a..33d0504c 100644 --- a/src/java.c +++ b/src/java.c @@ -1363,12 +1363,9 @@ static jint JNICALL cjni_api_dispatch_values (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_dispatch_notification (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_notification) { - notification_t n; + notification_t n = { 0 }; int status; - memset (&n, 0, sizeof (n)); - n.meta = NULL; - status = jtoc_notification (jvm_env, &n, o_notification); if (status != 0) { @@ -1423,7 +1420,7 @@ static jint JNICALL cjni_api_register_init (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_read) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_read, CB_TYPE_READ); @@ -1432,7 +1429,6 @@ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new read callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1447,7 +1443,7 @@ static jint JNICALL cjni_api_register_read (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_write) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_write, CB_TYPE_WRITE); @@ -1456,7 +1452,6 @@ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new write callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1470,7 +1465,7 @@ static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_flush) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_flush, CB_TYPE_FLUSH); @@ -1479,7 +1474,6 @@ static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new flush callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1500,7 +1494,7 @@ static jint JNICALL cjni_api_register_shutdown (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_log) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_log, CB_TYPE_LOG); @@ -1509,7 +1503,6 @@ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new log callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1523,7 +1516,7 @@ static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */ static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */ jobject this, jobject o_name, jobject o_notification) { - user_data_t ud; + user_data_t ud = { 0 }; cjni_callback_info_t *cbi; cbi = cjni_callback_info_create (jvm_env, o_name, o_notification, @@ -1533,7 +1526,6 @@ static jint JNICALL cjni_api_register_notification (JNIEnv *jvm_env, /* {{{ */ DEBUG ("java plugin: Registering new notification callback: %s", cbi->name); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) cbi; ud.free_func = cjni_callback_info_destroy; @@ -1567,9 +1559,8 @@ static jint JNICALL cjni_api_register_match_target (JNIEnv *jvm_env, /* {{{ */ if (type == CB_TYPE_MATCH) { - match_proc_t m_proc; + match_proc_t m_proc = { 0 }; - memset (&m_proc, 0, sizeof (m_proc)); m_proc.create = cjni_match_target_create; m_proc.destroy = cjni_match_target_destroy; m_proc.match = (void *) cjni_match_target_invoke; @@ -1578,9 +1569,8 @@ static jint JNICALL cjni_api_register_match_target (JNIEnv *jvm_env, /* {{{ */ } else if (type == CB_TYPE_TARGET) { - target_proc_t t_proc; + target_proc_t t_proc = { 0 }; - memset (&t_proc, 0, sizeof (t_proc)); t_proc.create = cjni_match_target_create; t_proc.destroy = cjni_match_target_destroy; t_proc.invoke = cjni_match_target_invoke; @@ -1985,7 +1975,7 @@ static int cjni_init_native (JNIEnv *jvm_env) /* {{{ */ static int cjni_create_jvm (void) /* {{{ */ { JNIEnv *jvm_env; - JavaVMInitArgs vm_args; + JavaVMInitArgs vm_args = { 0 }; JavaVMOption vm_options[jvm_argc]; int status; @@ -2004,7 +1994,6 @@ static int cjni_create_jvm (void) /* {{{ */ jvm_env = NULL; - memset (&vm_args, 0, sizeof (vm_args)); vm_args.version = JNI_VERSION_1_2; vm_args.options = vm_options; vm_args.nOptions = (jint) jvm_argc; @@ -2085,11 +2074,10 @@ static JNIEnv *cjni_thread_attach (void) /* {{{ */ else { int status; - JavaVMAttachArgs args; + JavaVMAttachArgs args = { 0 }; assert (cjni_env->jvm_env == NULL); - memset (&args, 0, sizeof (args)); args.version = JNI_VERSION_1_2; status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, (void *) &args); @@ -2920,9 +2908,8 @@ static int cjni_match_target_invoke (const data_set_t *ds, /* {{{ */ * `value_list_t'. */ if (cbi->type == CB_TYPE_TARGET) { - value_list_t new_vl; + value_list_t new_vl = { 0 }; - memset (&new_vl, 0, sizeof (new_vl)); status = jtoc_value_list (jvm_env, &new_vl, o_vl); if (status != 0) { @@ -3001,7 +2988,7 @@ static int cjni_shutdown_plugins (JNIEnv *jvm_env) /* {{{ */ static int cjni_shutdown (void) /* {{{ */ { JNIEnv *jvm_env; - JavaVMAttachArgs args; + JavaVMAttachArgs args = { 0 }; int status; size_t i; @@ -3009,7 +2996,6 @@ static int cjni_shutdown (void) /* {{{ */ return (0); jvm_env = NULL; - memset (&args, 0, sizeof (args)); args.version = JNI_VERSION_1_2; status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, &args); diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 77fd576e..f5eda6d2 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -266,13 +266,11 @@ static int lcc_send (lcc_connection_t *c, const char *command) /* {{{ */ static int lcc_receive (lcc_connection_t *c, /* {{{ */ lcc_response_t *ret_res) { - lcc_response_t res; + lcc_response_t res = { 0 }; char *ptr; char buffer[4096]; size_t i; - memset (&res, 0, sizeof (res)); - /* Read the first line, containing the status and a message */ ptr = fgets (buffer, sizeof (buffer), c->fh); if (ptr == NULL) @@ -358,7 +356,7 @@ static int lcc_receive (lcc_connection_t *c, /* {{{ */ static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */ const char *command, lcc_response_t *ret_res) { - lcc_response_t res; + lcc_response_t res = { 0 }; int status; if (c->fh == NULL) @@ -371,7 +369,6 @@ static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */ if (status != 0) return (status); - memset (&res, 0, sizeof (res)); status = lcc_receive (c, &res); if (status == 0) memcpy (ret_res, &res, sizeof (*ret_res)); @@ -381,7 +378,7 @@ static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */ static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */ { - struct sockaddr_un sa; + struct sockaddr_un sa = { 0 }; int fd; int status; @@ -398,7 +395,6 @@ static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */ return (-1); } - memset (&sa, 0, sizeof (sa)); sa.sun_family = AF_UNIX; strncpy (sa.sun_path, path, sizeof (sa.sun_path) - 1); @@ -424,7 +420,7 @@ static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */ const char *addr_orig) { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_res; struct addrinfo *ai_ptr; char addr_copy[NI_MAXHOST]; @@ -441,8 +437,6 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */ addr_copy[sizeof(addr_copy) - 1] = '\0'; addr = addr_copy; - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif diff --git a/src/libcollectdclient/network.c b/src/libcollectdclient/network.c index 4564fbbe..1a6c0f15 100644 --- a/src/libcollectdclient/network.c +++ b/src/libcollectdclient/network.c @@ -204,7 +204,7 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ static int server_send_buffer (lcc_server_t *srv) /* {{{ */ { - char buffer[LCC_NETWORK_BUFFER_SIZE_DEFAULT]; + char buffer[LCC_NETWORK_BUFFER_SIZE_DEFAULT] = { 0 }; size_t buffer_size; int status; @@ -215,7 +215,6 @@ static int server_send_buffer (lcc_server_t *srv) /* {{{ */ return (status); } - memset (buffer, 0, sizeof (buffer)); buffer_size = sizeof (buffer); status = lcc_network_buffer_finalize (srv->buffer); @@ -413,18 +412,16 @@ int lcc_server_set_interface (lcc_server_t *srv, char const *interface) /* {{{ * * index is preferred here, because of its similarity * to the way IPv6 handles this. Unfortunately, it * appears not to be portable. */ - struct ip_mreqn mreq; - - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_address.s_addr = ntohl (INADDR_ANY); - mreq.imr_ifindex = (int) if_index; + struct ip_mreqn mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_address.s_addr = ntohl (INADDR_ANY), + .imr_ifindex = (int) if_index + }; #else - struct ip_mreq mreq; - - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_interface.s_addr = ntohl (INADDR_ANY); + struct ip_mreq mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_interface.s_addr = ntohl (INADDR_ANY) + } #endif status = setsockopt (srv->fd, IPPROTO_IP, IP_MULTICAST_IF, diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 49f5576f..9a9c89ac 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -761,7 +761,8 @@ int lcc_network_buffer_initialize (lcc_network_buffer_t *nb) /* {{{ */ uint16_t pkg_type = htons (TYPE_ENCR_AES256); uint16_t pkg_length = 0; /* Filled in in finalize. */ uint16_t pkg_user_len = htons ((uint16_t) username_length); - char hash[20]; + /* Filled in in finalize. */ + char hash[20] = { 0 }; nb->encr_header_len = username_length; nb->encr_header_len += PART_ENCRYPTION_AES256_SIZE; @@ -769,9 +770,6 @@ int lcc_network_buffer_initialize (lcc_network_buffer_t *nb) /* {{{ */ gcry_randomize ((void *) &nb->encr_iv, sizeof (nb->encr_iv), GCRY_STRONG_RANDOM); - /* Filled in in finalize. */ - memset (hash, 0, sizeof (hash)); - ADD_STATIC (nb, pkg_type); ADD_STATIC (nb, pkg_length); ADD_STATIC (nb, pkg_user_len); diff --git a/src/madwifi.c b/src/madwifi.c index 6eb12dd2..ffc815da 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -699,7 +699,6 @@ process_80211stats (int sk, const char *dev) static int process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) { - struct iwreq iwr; static char mac[DATA_MAX_NAME_LEN]; struct ieee80211req_sta_stats stats; const struct ieee80211_nodestats *ns = &stats.is_stats; @@ -714,10 +713,12 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) if (item_watched (STAT_NODE_RSSI)) submit_gauge (dev, "node_rssi", mac, NULL, si->isi_rssi); - memset (&iwr, 0, sizeof (iwr)); + struct iwreq iwr = { + .u.data.pointer = (void *) &stats, + .u.data.length = sizeof (stats) + }; sstrncpy(iwr.ifr_name, dev, sizeof (iwr.ifr_name)); - iwr.u.data.pointer = (void *) &stats; - iwr.u.data.length = sizeof (stats); + memcpy(stats.is_u.macaddr, si->isi_macaddr, IEEE80211_ADDR_LEN); status = ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr); if (status < 0) @@ -751,16 +752,16 @@ static int process_stations (int sk, const char *dev) { uint8_t buf[24*1024]; - struct iwreq iwr; uint8_t *cp; int nodes; size_t len; int status; - memset (&iwr, 0, sizeof (iwr)); + struct iwreq iwr = { + .u.data.pointer = (void *) buf, + .u.data.length = sizeof (buf) + }; sstrncpy (iwr.ifr_name, dev, sizeof (iwr.ifr_name)); - iwr.u.data.pointer = (void *) buf; - iwr.u.data.length = sizeof (buf); status = ioctl (sk, IEEE80211_IOCTL_STA_INFO, &iwr); if (status < 0) diff --git a/src/match_hashed.c b/src/match_hashed.c index 79f79fac..a42439c0 100644 --- a/src/match_hashed.c +++ b/src/match_hashed.c @@ -175,9 +175,8 @@ static int mh_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ void module_register (void) { - match_proc_t mproc; + match_proc_t mproc = { 0 }; - memset (&mproc, 0, sizeof (mproc)); mproc.create = mh_create; mproc.destroy = mh_destroy; mproc.match = mh_match; diff --git a/src/match_regex.c b/src/match_regex.c index bbc35cd4..2dee9a8f 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -303,9 +303,8 @@ static int mr_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ void module_register (void) { - match_proc_t mproc; + match_proc_t mproc = { 0 }; - memset (&mproc, 0, sizeof (mproc)); mproc.create = mr_create; mproc.destroy = mr_destroy; mproc.match = mr_match; diff --git a/src/match_timediff.c b/src/match_timediff.c index 750817be..3b154150 100644 --- a/src/match_timediff.c +++ b/src/match_timediff.c @@ -144,9 +144,8 @@ static int mt_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ void module_register (void) { - match_proc_t mproc; + match_proc_t mproc = { 0 }; - memset (&mproc, 0, sizeof (mproc)); mproc.create = mt_create; mproc.destroy = mt_destroy; mproc.match = mt_match; diff --git a/src/match_value.c b/src/match_value.c index 599f1cfb..3b269c8c 100644 --- a/src/match_value.c +++ b/src/match_value.c @@ -349,9 +349,8 @@ static int mv_match (const data_set_t *ds, const value_list_t *vl, /* {{{ */ void module_register (void) { - match_proc_t mproc; + match_proc_t mproc = { 0 }; - memset (&mproc, 0, sizeof (mproc)); mproc.create = mv_create; mproc.destroy = mv_destroy; mproc.match = mv_match; diff --git a/src/mbmon.c b/src/mbmon.c index 2d6d77e2..ccececd7 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -84,12 +84,10 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) const char *host; const char *port; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list, *ai_ptr; int ai_return; - memset (&ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif diff --git a/src/memcached.c b/src/memcached.c index 54e3a190..faff5793 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -67,10 +67,9 @@ static void memcached_free (void *arg) static int memcached_connect_unix (memcached_t *st) { - struct sockaddr_un serv_addr; + struct sockaddr_un serv_addr = { 0 }; int fd; - memset (&serv_addr, 0, sizeof (serv_addr)); serv_addr.sun_family = AF_UNIX; sstrncpy (serv_addr.sun_path, st->socket, sizeof (serv_addr.sun_path)); @@ -102,13 +101,11 @@ static int memcached_connect_inet (memcached_t *st) const char *host; const char *port; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list, *ai_ptr; int status; int fd = -1; - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -551,11 +548,10 @@ static int memcached_read (user_data_t *user_data) static int memcached_add_read_callback (memcached_t *st) { - user_data_t ud; + user_data_t ud = { 0 }; char callback_name[3*DATA_MAX_NAME_LEN]; int status; - memset (&ud, 0, sizeof (ud)); ud.data = st; ud.free_func = memcached_free; diff --git a/src/memory.c b/src/memory.c index 3d8a867a..744af1a8 100644 --- a/src/memory.c +++ b/src/memory.c @@ -456,13 +456,12 @@ static int memory_read_internal (value_list_t *vl) #elif HAVE_SYSCTL int mib[] = {CTL_VM, VM_METER}; - struct vmtotal vmtotal; + struct vmtotal vmtotal = { 0 }; gauge_t mem_active; gauge_t mem_inactive; gauge_t mem_free; size_t size; - memset (&vmtotal, 0, sizeof (vmtotal)); size = sizeof (vmtotal); if (sysctl (mib, 2, &vmtotal, &size, NULL, 0) < 0) { @@ -495,9 +494,8 @@ static int memory_read_internal (value_list_t *vl) /* #endif HAVE_LIBSTATGRAB */ #elif HAVE_PERFSTAT - perfstat_memory_total_t pmemory; + perfstat_memory_total_t pmemory = { 0 }; - memset (&pmemory, 0, sizeof (pmemory)); if (perfstat_memory_total(NULL, &pmemory, sizeof(pmemory), 1) < 0) { char errbuf[1024]; diff --git a/src/modbus.c b/src/modbus.c index 11b9bf1b..809194b4 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -427,7 +427,7 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ mb_data_t *data) { - uint16_t values[2]; + uint16_t values[2] = { 0 }; int values_num; const data_set_t *ds; int status = 0; @@ -459,7 +459,6 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ "is not UINT32.", data->type, DS_TYPE_TO_STRING (ds->ds[0].type)); } - memset (values, 0, sizeof (values)); if ((data->register_type == REG_TYPE_INT32) || (data->register_type == REG_TYPE_UINT32) || (data->register_type == REG_TYPE_FLOAT)) @@ -720,11 +719,10 @@ static void host_free (void *void_host) /* {{{ */ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ { - mb_data_t data; + mb_data_t data = { 0 }; int status; int i; - memset (&data, 0, sizeof (data)); data.name = NULL; data.register_type = REG_TYPE_UINT16; data.next = NULL; @@ -820,13 +818,12 @@ static int mb_config_set_host_address (mb_host_t *host, /* {{{ */ { struct addrinfo *ai_list; struct addrinfo *ai_ptr; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; int status; if ((host == NULL) || (address == NULL)) return (EINVAL); - memset (&ai_hints, 0, sizeof (ai_hints)); #if AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif diff --git a/src/mqtt.c b/src/mqtt.c index 7516db48..b318f211 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -549,7 +549,7 @@ static int mqtt_config_publisher (oconfig_item_t *ci) { mqtt_client_conf_t *conf; char cb_name[1024]; - user_data_t user_data; + user_data_t user_data = { 0 }; int status; int i; @@ -634,7 +634,6 @@ static int mqtt_config_publisher (oconfig_item_t *ci) } ssnprintf (cb_name, sizeof (cb_name), "mqtt/%s", conf->name); - memset (&user_data, 0, sizeof (user_data)); user_data.data = conf; plugin_register_write (cb_name, mqtt_write, &user_data); diff --git a/src/multimeter.c b/src/multimeter.c index 69537505..00e9964b 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -157,11 +157,10 @@ static int multimeter_init (void) if ((fd = open(device, O_RDWR | O_NOCTTY)) != -1) { - struct termios tios; + struct termios tios = { 0 }; int rts = TIOCM_RTS; double value; - memset (&tios, 0, sizeof (tios)); tios.c_cflag = B1200 | CS7 | CSTOPB | CREAD | CLOCAL; tios.c_iflag = IGNBRK | IGNPAR; tios.c_oflag = 0; diff --git a/src/mysql.c b/src/mysql.c index 8ab775fc..419a1543 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -191,13 +191,12 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ /* If all went well, register this database for reading */ if (status == 0) { - user_data_t ud; + user_data_t ud = { 0 }; char cb_name[DATA_MAX_NAME_LEN]; DEBUG ("mysql plugin: Registering new read callback: %s", (db->database != NULL) ? db->database : ""); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = mysql_database_free; diff --git a/src/netapp.c b/src/netapp.c index e00c2529..45395ae0 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -889,15 +889,13 @@ static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */ na_elem_t *data, cdtime_t interval) { - cfg_wafl_t perf_data; + cfg_wafl_t perf_data = { 0 }; const char *plugin_inst; na_elem_t *instances; na_elem_t *counter; na_elem_iter_t counter_iter; - memset (&perf_data, 0, sizeof (perf_data)); - perf_data.timestamp = cna_child_get_cdtime (data); instances = na_elem_child(na_elem_child (data, "instances"), "instance-data"); @@ -1081,12 +1079,11 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ instance = na_iterator_next(&instance_iter)) { disk_t *old_data; - disk_t new_data; + disk_t new_data = { 0 }; na_elem_iter_t counter_iterator; na_elem_t *counter; - memset (&new_data, 0, sizeof (new_data)); new_data.timestamp = timestamp; new_data.disk_busy_percent = NAN; @@ -1273,14 +1270,13 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ { const char *name; - data_volume_perf_t perf_data; + data_volume_perf_t perf_data = { 0 }; data_volume_perf_t *v; na_elem_t *elem_counters; na_elem_iter_t iter_counters; na_elem_t *elem_counter; - memset (&perf_data, 0, sizeof (perf_data)); perf_data.timestamp = timestamp; name = na_child_get_string (elem_instance, "name"); @@ -1519,9 +1515,8 @@ static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */ static int cna_change_volume_status (const char *hostname, /* {{{ */ data_volume_usage_t *v) { - notification_t n; + notification_t n = { 0 }; - memset (&n, 0, sizeof (n)); n.time = cdtime (); sstrncpy (n.host, hostname, sizeof (n.host)); sstrncpy (n.plugin, "netapp", sizeof (n.plugin)); @@ -2895,7 +2890,7 @@ static int cna_read (user_data_t *ud); static int cna_register_host (host_config_t *host) /* {{{ */ { char cb_name[256]; - user_data_t ud; + user_data_t ud = { 0 }; if (host->vfiler) ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s", @@ -2903,7 +2898,6 @@ static int cna_register_host (host_config_t *host) /* {{{ */ else ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name); - memset (&ud, 0, sizeof (ud)); ud.data = host; ud.free_func = (void (*) (void *)) free_host_config; @@ -3074,9 +3068,8 @@ static int cna_init_host (host_config_t *host) /* {{{ */ static int cna_init (void) /* {{{ */ { - char err[256]; + char err[256] = { 0 }; - memset (err, 0, sizeof (err)); if (!na_startup(err, sizeof(err))) { err[sizeof (err) - 1] = 0; ERROR("netapp plugin: Error initializing netapp API: %s", err); diff --git a/src/network.c b/src/network.c index 4393d08a..5a8a88ef 100644 --- a/src/network.c +++ b/src/network.c @@ -1227,7 +1227,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ size_t buffer_offset; uint16_t username_len; part_encryption_aes256_t pea; - unsigned char hash[sizeof (pea.hash)]; + unsigned char hash[sizeof (pea.hash)] = { 0 }; gcry_cipher_hd_t cypher; gcry_error_t err; @@ -1314,7 +1314,6 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ assert (buffer_offset == (part_size - payload_len)); /* Check hash sum */ - memset (hash, 0, sizeof (hash)); gcry_md_hash_buffer (GCRY_MD_SHA1, hash, buffer + buffer_offset, payload_len); if (memcmp (hash, pea.hash, sizeof (hash)) != 0) @@ -1395,7 +1394,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ int status; value_list_t vl = VALUE_LIST_INIT; - notification_t n; + notification_t n = { 0 }; #if HAVE_LIBGCRYPT int packet_was_signed = (flags & PP_SIGNED); @@ -1405,7 +1404,6 @@ static int parse_packet (sockent_t *se, /* {{{ */ memset (&vl, '\0', sizeof (vl)); - memset (&n, '\0', sizeof (n)); status = 0; while ((status == 0) && (0 < buffer_size) @@ -1779,18 +1777,16 @@ static int network_set_interface (const sockent_t *se, const struct addrinfo *ai * index is preferred here, because of its similarity * to the way IPv6 handles this. Unfortunately, it * appears not to be portable. */ - struct ip_mreqn mreq; - - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_address.s_addr = ntohl (INADDR_ANY); - mreq.imr_ifindex = se->interface; + struct ip_mreqn mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_address.s_addr = ntohl (INADDR_ANY), + .imr_ifindex = se->interface + }; #else - struct ip_mreq mreq; - - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_interface.s_addr = ntohl (INADDR_ANY); + struct ip_mreq mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_interface.s_addr = ntohl (INADDR_ANY) + }; #endif if (setsockopt (se->data.client.fd, IPPROTO_IP, IP_MULTICAST_IF, @@ -2143,7 +2139,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ static c_complain_t complaint = C_COMPLAIN_INIT_STATIC; struct sockent_client *client; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list = NULL, *ai_ptr; int status; _Bool reconnect = 0; @@ -2164,7 +2160,6 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ if (client->fd >= 0 && !reconnect) /* already connected and not stale*/ return (0); - memset (&ai_hints, 0, sizeof (ai_hints)); #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -2241,7 +2236,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ /* Open the file descriptors for a initialized sockent structure. */ static int sockent_server_listen (sockent_t *se) /* {{{ */ { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list, *ai_ptr; int status; @@ -2263,8 +2258,6 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */ DEBUG ("network plugin: sockent_server_listen: node = %s; service = %s;", node, service); - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_PASSIVE ai_hints.ai_flags |= AI_PASSIVE; #endif @@ -2639,7 +2632,6 @@ static void network_send_buffer_plain (sockent_t *se, /* {{{ */ static void network_send_buffer_signed (sockent_t *se, /* {{{ */ const char *in_buffer, size_t in_buffer_size) { - part_signature_sha256_t ps; char buffer[BUFF_SIG_SIZE + in_buffer_size]; size_t buffer_offset; size_t username_len; @@ -2681,9 +2673,10 @@ static void network_send_buffer_signed (sockent_t *se, /* {{{ */ in_buffer, in_buffer_size); /* Initialize the `ps' structure. */ - memset (&ps, 0, sizeof (ps)); - ps.head.type = htons (TYPE_SIGN_SHA256); - ps.head.length = htons (PART_SIGNATURE_SHA256_SIZE + username_len); + part_signature_sha256_t ps = { + .head.type = htons (TYPE_SIGN_SHA256), + .head.length = htons (PART_SIGNATURE_SHA256_SIZE + username_len) + }; /* Calculate the hash value. */ gcry_md_write (hd, buffer + PART_SIGNATURE_SHA256_SIZE, @@ -2716,7 +2709,6 @@ static void network_send_buffer_signed (sockent_t *se, /* {{{ */ static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */ const char *in_buffer, size_t in_buffer_size) { - part_encryption_aes256_t pea; char buffer[BUFF_SIG_SIZE + in_buffer_size]; size_t buffer_size; size_t buffer_offset; @@ -2726,10 +2718,10 @@ static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */ gcry_cipher_hd_t cypher; /* Initialize the header fields */ - memset (&pea, 0, sizeof (pea)); - pea.head.type = htons (TYPE_ENCR_AES256); - - pea.username = se->data.client.username; + part_encryption_aes256_t pea = { + .head.type = htons (TYPE_ENCR_AES256), + .username = se->data.client.username + }; username_len = strlen (pea.username); if ((PART_ENCRYPTION_AES256_SIZE + username_len) > BUFF_SIG_SIZE) diff --git a/src/notify_nagios.c b/src/notify_nagios.c index 1f4182bb..c1692223 100644 --- a/src/notify_nagios.c +++ b/src/notify_nagios.c @@ -63,7 +63,7 @@ static int nagios_print (char const *buffer) /* {{{ */ char const *file = NAGIOS_COMMAND_FILE; int fd; int status; - struct flock lock; + struct flock lock = { 0 }; if (nagios_command_file != NULL) file = nagios_command_file; @@ -78,11 +78,8 @@ static int nagios_print (char const *buffer) /* {{{ */ return status; } - memset (&lock, 0, sizeof (lock)); lock.l_type = F_WRLCK; lock.l_whence = SEEK_END; - lock.l_start = 0; - lock.l_len = 0; /* to end of file */ status = fcntl (fd, F_GETLK, &lock); if (status != 0) diff --git a/src/ntpd.c b/src/ntpd.c index f8f4f049..f7b57ba3 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -346,7 +346,7 @@ static int ntpd_connect (void) const char *host; const char *port; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list; struct addrinfo *ai_ptr; int status; @@ -364,8 +364,6 @@ static int ntpd_connect (void) if (strlen (port) == 0) port = NTPD_DEFAULT_PORT; - memset (&ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -431,13 +429,13 @@ static int ntpd_receive_response (int *res_items, int *res_size, struct timeval time_now; int timeout; - int pkt_item_num; /* items in this packet */ - int pkt_item_len; /* size of the items in this packet */ + int pkt_item_num; /* items in this packet */ + int pkt_item_len; /* size of the items in this packet */ int pkt_sequence; - char pkt_recvd[MAXSEQ+1]; /* sequence numbers that have been received */ - int pkt_recvd_num; /* number of packets that have been received */ - int pkt_lastseq; /* the last sequence number */ - ssize_t pkt_padding; /* Padding in this packet */ + char pkt_recvd[MAXSEQ+1] = { 0 }; /* sequence numbers that have been received */ + int pkt_recvd_num; /* number of packets that have been received */ + int pkt_lastseq; /* the last sequence number */ + ssize_t pkt_padding; /* Padding in this packet */ if ((sd = ntpd_connect ()) < 0) return (-1); @@ -445,7 +443,6 @@ static int ntpd_receive_response (int *res_items, int *res_size, items = NULL; items_num = 0; - memset (pkt_recvd, '\0', sizeof (pkt_recvd)); pkt_recvd_num = 0; pkt_lastseq = -1; @@ -714,7 +711,7 @@ static int ntpd_receive_response (int *res_items, int *res_size, static int ntpd_send_request (int req_code, int req_items, int req_size, char *req_data) { int sd; - struct req_pkt req; + struct req_pkt req = { 0 }; size_t req_data_len; int status; @@ -724,7 +721,6 @@ static int ntpd_send_request (int req_code, int req_items, int req_size, char *r if ((sd = ntpd_connect ()) < 0) return (-1); - memset (&req, '\0', sizeof (req)); req.rm_vn_mode = RM_VN_MODE(0, 0, 0); req.auth_seq = AUTH_SEQ (0, 0); req.implementation = IMPL_XNTPD; @@ -805,20 +801,17 @@ static uint32_t ntpd_get_refclock_id (struct info_peer_summary const *peer_info) static int ntpd_get_name_from_address (char *buffer, size_t buffer_size, struct info_peer_summary const *peer_info, _Bool do_reverse_lookup) { - struct sockaddr_storage sa; + struct sockaddr_storage sa = { 0 }; socklen_t sa_len; int flags = 0; int status; - memset (&sa, 0, sizeof (sa)); - if (peer_info->v6_flag) { - struct sockaddr_in6 sa6; + struct sockaddr_in6 sa6 = { 0 }; assert (sizeof (sa) >= sizeof (sa6)); - memset (&sa6, 0, sizeof (sa6)); sa6.sin6_family = AF_INET6; sa6.sin6_port = htons (123); memcpy (&sa6.sin6_addr, &peer_info->srcadr6, @@ -829,11 +822,10 @@ static int ntpd_get_name_from_address (char *buffer, size_t buffer_size, } else { - struct sockaddr_in sa4; + struct sockaddr_in sa4 = { 0 }; assert (sizeof (sa) >= sizeof (sa4)); - memset (&sa4, 0, sizeof (sa4)); sa4.sin_family = AF_INET; sa4.sin_port = htons (123); memcpy (&sa4.sin_addr, &peer_info->srcadr, diff --git a/src/numa.c b/src/numa.c index a87a17e9..4bcc2468 100644 --- a/src/numa.c +++ b/src/numa.c @@ -130,11 +130,10 @@ static int numa_init (void) /* {{{ */ while (42) { char path[PATH_MAX]; - struct stat statbuf; + struct stat statbuf = { 0 }; int status; ssnprintf (path, sizeof (path), NUMA_ROOT_DIR "/node%i", max_node + 1); - memset (&statbuf, 0, sizeof (statbuf)); status = stat (path, &statbuf); if (status == 0) diff --git a/src/olsrd.c b/src/olsrd.c index 6d22d98a..2b7e767e 100644 --- a/src/olsrd.c +++ b/src/olsrd.c @@ -149,14 +149,12 @@ static size_t strtabsplit (char *string, char **fields, size_t size) /* {{{ */ static FILE *olsrd_connect (void) /* {{{ */ { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list, *ai_ptr; int ai_return; FILE *fh; - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -557,9 +555,8 @@ static int olsrd_cb_topology (int lineno, /* {{{ */ if (config_want_topology == OLSRD_WANT_DETAIL) { - char type_instance[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN] = { 0 }; - memset (type_instance, 0, sizeof (type_instance)); ssnprintf (type_instance, sizeof (type_instance), "%s-%s-lq", fields[0], fields[1]); DEBUG ("olsrd plugin: type_instance = %s; lq = %g;", type_instance, lq); @@ -581,9 +578,8 @@ static int olsrd_cb_topology (int lineno, /* {{{ */ } else { - char type_instance[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN] = { 0 }; - memset (type_instance, 0, sizeof (type_instance)); ssnprintf (type_instance, sizeof (type_instance), "%s-%s-nlq", fields[0], fields[1]); DEBUG ("olsrd plugin: type_instance = %s; nlq = %g;", type_instance, nlq); diff --git a/src/openldap.c b/src/openldap.c index 151d25d7..3dac057e 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -653,17 +653,15 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ } else { - user_data_t ud; - char callback_name[3*DATA_MAX_NAME_LEN]; + user_data_t ud = { 0 }; + char callback_name[3*DATA_MAX_NAME_LEN] = { 0 }; databases = temp; databases[databases_num] = st; databases_num++; - memset (&ud, 0, sizeof (ud)); ud.data = st; - memset (callback_name, 0, sizeof (callback_name)); ssnprintf (callback_name, sizeof (callback_name), "openldap/%s/%s", (st->host != NULL) ? st->host : hostname_g, diff --git a/src/perl.c b/src/perl.c index 7d78630e..fe9f97b5 100644 --- a/src/perl.c +++ b/src/perl.c @@ -983,15 +983,13 @@ static int pplugin_write (pTHX_ const char *plugin, AV *data_set, HV *values) */ static int pplugin_dispatch_notification (pTHX_ HV *notif) { - notification_t n; + notification_t n = { 0 }; int ret; if (NULL == notif) return -1; - memset (&n, 0, sizeof (n)); - if (0 != hv2notification (aTHX_ notif, &n)) return -1; diff --git a/src/pf.c b/src/pf.c index 225d536e..42679feb 100644 --- a/src/pf.c +++ b/src/pf.c @@ -79,7 +79,7 @@ static void pf_submit (char const *type, char const *type_instance, static int pf_read (void) { - struct pf_status state; + struct pf_status state = { 0 }; int fd; int status; int i; @@ -94,7 +94,6 @@ static int pf_read (void) return (-1); } - memset (&state, 0, sizeof (state)); status = ioctl (fd, DIOCGETSTATUS, &state); if (status != 0) { diff --git a/src/pinba.c b/src/pinba.c index cfc07774..833fa1b8 100644 --- a/src/pinba.c +++ b/src/pinba.c @@ -352,10 +352,9 @@ static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */ pinba_socket_t *s; struct addrinfo *ai_list; struct addrinfo *ai_ptr; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; int status; - memset (&ai_hints, 0, sizeof (ai_hints)); ai_hints.ai_flags = AI_PASSIVE; ai_hints.ai_family = AF_UNSPEC; ai_hints.ai_socktype = SOCK_DGRAM; diff --git a/src/postgresql.c b/src/postgresql.c index 41ce95cd..65766a9f 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -1188,7 +1188,7 @@ static int c_psql_config_database (oconfig_item_t *ci) c_psql_database_t *db; char cb_name[DATA_MAX_NAME_LEN]; - user_data_t ud; + user_data_t ud = { 0 }; static _Bool have_flush = 0; @@ -1200,8 +1200,6 @@ static int c_psql_config_database (oconfig_item_t *ci) return 1; } - memset (&ud, 0, sizeof (ud)); - db = c_psql_database_new (ci->values[0].value.string); if (db == NULL) return -1; diff --git a/src/powerdns.c b/src/powerdns.c index f72bd40f..55f13fef 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -375,7 +375,7 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ char *buffer = NULL; size_t buffer_size = 0; - struct sockaddr_un sa_unix; + struct sockaddr_un sa_unix = { 0 }; struct timeval stv_timeout; cdtime_t cdt_timeout; @@ -387,7 +387,6 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ return (-1); } - memset (&sa_unix, 0, sizeof (sa_unix)); sa_unix.sun_family = AF_UNIX; sstrncpy (sa_unix.sun_path, (local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH, diff --git a/src/python.c b/src/python.c index 61d464d8..3a282918 100644 --- a/src/python.c +++ b/src/python.c @@ -623,7 +623,7 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, PyObjec char buf[512]; reg_function_t *register_function = (reg_function_t *) reg; cpy_callback_t *c = NULL; - user_data_t user_data; + user_data_t user_data = { 0 }; char *name = NULL; PyObject *callback = NULL, *data = NULL; static char *kwlist[] = {"callback", "data", "name", NULL}; @@ -649,7 +649,6 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, PyObjec c->data = data; c->next = NULL; - memset (&user_data, 0, sizeof (user_data)); user_data.free_func = cpy_destroy_user_data; user_data.data = c; @@ -660,7 +659,7 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, PyObjec static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwds) { char buf[512]; cpy_callback_t *c = NULL; - user_data_t user_data; + user_data_t user_data = { 0 }; double interval = 0; char *name = NULL; PyObject *callback = NULL, *data = NULL; @@ -687,7 +686,6 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd c->data = data; c->next = NULL; - memset (&user_data, 0, sizeof (user_data)); user_data.free_func = cpy_destroy_user_data; user_data.data = c; @@ -920,7 +918,7 @@ static void cpy_int_handler(int sig) { static void *cpy_interactive(void *data) { sigset_t sigset; - struct sigaction sig_int_action, old; + struct sigaction old; /* Signal handler in a plugin? Bad stuff, but the best way to * handle it I guess. In an interactive session people will @@ -938,8 +936,9 @@ static void *cpy_interactive(void *data) { * still interrupt syscalls like sleep and pause. * It does not raise a KeyboardInterrupt exception because so * far nobody managed to figure out how to do that. */ - memset (&sig_int_action, '\0', sizeof (sig_int_action)); - sig_int_action.sa_handler = cpy_int_handler; + struct sigaction sig_int_action = { + .sa_handler = cpy_int_handler + }; sigaction (SIGINT, &sig_int_action, &old); sigemptyset(&sigset); diff --git a/src/redis.c b/src/redis.c index 2d0bd958..47d0d707 100644 --- a/src/redis.c +++ b/src/redis.c @@ -165,17 +165,17 @@ static redis_query_t *redis_config_query (oconfig_item_t *ci) /* {{{ */ static int redis_config_node (oconfig_item_t *ci) /* {{{ */ { - redis_node_t rn; redis_query_t *rq; int i; int status; int timeout; - memset (&rn, 0, sizeof (rn)); + redis_node_t rn = { + .port = REDIS_DEF_PORT, + .timeout.tv_usec = REDIS_DEF_TIMEOUT + }; + sstrncpy (rn.host, REDIS_DEF_HOST, sizeof (rn.host)); - rn.port = REDIS_DEF_PORT; - rn.timeout.tv_usec = REDIS_DEF_TIMEOUT; - rn.queries = NULL; status = cf_util_get_string_buffer (ci, rn.name, sizeof (rn.name)); if (status != 0) diff --git a/src/snmp.c b/src/snmp.c index 6a5bb8b9..08492558 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -641,7 +641,7 @@ static int csnmp_config_add_host (oconfig_item_t *ci) /* Registration stuff. */ char cb_name[DATA_MAX_NAME_LEN]; - user_data_t cb_data; + user_data_t cb_data = { 0 }; hd = calloc (1, sizeof (*hd)); if (hd == NULL) @@ -772,7 +772,6 @@ static int csnmp_config_add_host (oconfig_item_t *ci) ssnprintf (cb_name, sizeof (cb_name), "snmp-%s", hd->name); - memset (&cb_data, 0, sizeof (cb_data)); cb_data.data = hd; cb_data.free_func = csnmp_host_definition_destroy; @@ -942,9 +941,8 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int type, } else { - char oid_buffer[1024]; + char oid_buffer[1024] = { 0 }; - memset (oid_buffer, 0, sizeof (oid_buffer)); snprint_objid (oid_buffer, sizeof (oid_buffer) - 1, vl->name, vl->name_length); @@ -1276,7 +1274,6 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat vl.interval = host->interval; have_more = 1; - memset (¤t_suffix, 0, sizeof (current_suffix)); while (have_more) { _Bool suffix_skipped = 0; diff --git a/src/statsd.c b/src/statsd.c index a0c6e4f3..1eb8cb94 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -500,7 +500,7 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ struct pollfd *fds = NULL; size_t fds_num = 0; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list = NULL; struct addrinfo *ai_ptr; int status; @@ -509,7 +509,6 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ char const *service = (conf_service != NULL) ? conf_service : STATSD_DEFAULT_SERVICE; - memset (&ai_hints, 0, sizeof (ai_hints)); ai_hints.ai_flags = AI_PASSIVE; #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; diff --git a/src/swap.c b/src/swap.c index d714b5fc..645dc586 100644 --- a/src/swap.c +++ b/src/swap.c @@ -761,14 +761,13 @@ static int swap_read (void) /* {{{ */ #elif HAVE_PERFSTAT static int swap_read (void) /* {{{ */ { - perfstat_memory_total_t pmemory; + perfstat_memory_total_t pmemory = { 0 }; int status; gauge_t total; gauge_t free; gauge_t reserved; - memset (&pmemory, 0, sizeof (pmemory)); status = perfstat_memory_total (NULL, &pmemory, sizeof(perfstat_memory_total_t), 1); if (status < 0) { diff --git a/src/tail.c b/src/tail.c index 5402f666..b9e92068 100644 --- a/src/tail.c +++ b/src/tail.c @@ -137,12 +137,10 @@ static int ctail_config_add_match_dstype (ctail_config_match_t *cm, static int ctail_config_add_match (cu_tail_match_t *tm, const char *plugin_instance, oconfig_item_t *ci, cdtime_t interval) { - ctail_config_match_t cm; + ctail_config_match_t cm = { 0 }; int status; int i; - memset (&cm, '\0', sizeof (cm)); - if (ci->values_num != 0) { WARNING ("tail plugin: Ignoring arguments for the `Match' block."); @@ -333,7 +331,7 @@ static int ctail_read (user_data_t *ud) static int ctail_init (void) { char str[255]; - user_data_t ud; + user_data_t ud = { 0 }; size_t i; if (tail_match_list_num == 0) @@ -342,8 +340,6 @@ static int ctail_init (void) return (-1); } - memset(&ud, '\0', sizeof(ud)); - for (i = 0; i < tail_match_list_num; i++) { ud.data = (void *)tail_match_list[i]; diff --git a/src/tail_csv.c b/src/tail_csv.c index a768ef81..70710216 100644 --- a/src/tail_csv.c +++ b/src/tail_csv.c @@ -423,7 +423,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) /* Registration variables */ char cb_name[DATA_MAX_NAME_LEN]; - user_data_t cb_data; + user_data_t cb_data = { 0 }; id = calloc(1, sizeof(*id)); if (id == NULL) @@ -484,7 +484,6 @@ static int tcsv_config_add_file(oconfig_item_t *ci) } ssnprintf (cb_name, sizeof (cb_name), "tail_csv/%s", id->path); - memset(&cb_data, 0, sizeof(cb_data)); cb_data.data = id; cb_data.free_func = tcsv_instance_definition_destroy; status = plugin_register_complex_read(NULL, cb_name, tcsv_read, id->interval, &cb_data); diff --git a/src/target_notification.c b/src/target_notification.c index 55b72ac1..63e4f315 100644 --- a/src/target_notification.c +++ b/src/target_notification.c @@ -192,7 +192,7 @@ static int tn_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ notification_meta_t __attribute__((unused)) **meta, void **user_data) { tn_data_t *data; - notification_t n; + notification_t n = { 0 }; char temp[NOTIF_MAX_MSG_LEN]; gauge_t *rates; @@ -211,7 +211,6 @@ static int tn_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ } /* Initialize the structure. */ - memset (&n, 0, sizeof (n)); n.severity = data->severity; n.time = cdtime (); sstrncpy (n.message, data->message, sizeof (n.message)); @@ -276,9 +275,8 @@ static int tn_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ void module_register (void) { - target_proc_t tproc; + target_proc_t tproc = { 0 }; - memset (&tproc, 0, sizeof (tproc)); tproc.create = tn_create; tproc.destroy = tn_destroy; tproc.invoke = tn_invoke; diff --git a/src/target_replace.c b/src/target_replace.c index 545fa353..8d774c57 100644 --- a/src/target_replace.c +++ b/src/target_replace.c @@ -158,13 +158,12 @@ static int tr_action_invoke (tr_action_t *act_head, /* {{{ */ tr_action_t *act; int status; char buffer[DATA_MAX_NAME_LEN]; - regmatch_t matches[8]; + regmatch_t matches[8] = { [0] = { 0 } }; if (act_head == NULL) return (-EINVAL); sstrncpy (buffer, buffer_in, sizeof (buffer)); - memset (matches, 0, sizeof (matches)); DEBUG ("target_replace plugin: tr_action_invoke: <- buffer = %s;", buffer); @@ -346,9 +345,8 @@ static int tr_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ void module_register (void) { - target_proc_t tproc; + target_proc_t tproc = { 0 }; - memset (&tproc, 0, sizeof (tproc)); tproc.create = tr_create; tproc.destroy = tr_destroy; tproc.invoke = tr_invoke; diff --git a/src/target_scale.c b/src/target_scale.c index 74652ff8..579d01a0 100644 --- a/src/target_scale.c +++ b/src/target_scale.c @@ -490,9 +490,8 @@ static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ void module_register (void) { - target_proc_t tproc; + target_proc_t tproc = { 0 }; - memset (&tproc, 0, sizeof (tproc)); tproc.create = ts_create; tproc.destroy = ts_destroy; tproc.invoke = ts_invoke; diff --git a/src/target_set.c b/src/target_set.c index 6115639b..2060dcde 100644 --- a/src/target_set.c +++ b/src/target_set.c @@ -256,9 +256,8 @@ static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ void module_register (void) { - target_proc_t tproc; + target_proc_t tproc = { 0 }; - memset (&tproc, 0, sizeof (tproc)); tproc.create = ts_create; tproc.destroy = ts_destroy; tproc.invoke = ts_invoke; diff --git a/src/target_v5upgrade.c b/src/target_v5upgrade.c index d85a181f..6d661711 100644 --- a/src/target_v5upgrade.c +++ b/src/target_v5upgrade.c @@ -463,9 +463,8 @@ static int v5_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ void module_register (void) { - target_proc_t tproc; + target_proc_t tproc = { 0 }; - memset (&tproc, 0, sizeof (tproc)); tproc.create = v5_create; tproc.destroy = v5_destroy; tproc.invoke = v5_invoke; diff --git a/src/tcpconns.c b/src/tcpconns.c index 6bc33842..da916950 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -485,10 +485,6 @@ static int conn_read_netlink (void) { #if HAVE_STRUCT_LINUX_INET_DIAG_REQ int fd; - struct sockaddr_nl nladdr; - struct nlreq req; - struct msghdr msg; - struct iovec iov; struct inet_diag_msg *r; char buf[8192]; @@ -503,34 +499,38 @@ static int conn_read_netlink (void) return (-1); } - memset(&nladdr, 0, sizeof(nladdr)); - nladdr.nl_family = AF_NETLINK; - - memset(&req, 0, sizeof(req)); - req.nlh.nlmsg_len = sizeof(req); - req.nlh.nlmsg_type = TCPDIAG_GETSOCK; - /* NLM_F_ROOT: return the complete table instead of a single entry. - * NLM_F_MATCH: return all entries matching criteria (not implemented) - * NLM_F_REQUEST: must be set on all request messages */ - req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; - req.nlh.nlmsg_pid = 0; - /* The sequence_number is used to track our messages. Since netlink is not - * reliable, we don't want to end up with a corrupt or incomplete old - * message in case the system is/was out of memory. */ - req.nlh.nlmsg_seq = ++sequence_number; - req.r.idiag_family = AF_INET; - req.r.idiag_states = 0xfff; - req.r.idiag_ext = 0; - - memset(&iov, 0, sizeof(iov)); - iov.iov_base = &req; - iov.iov_len = sizeof(req); - - memset(&msg, 0, sizeof(msg)); - msg.msg_name = (void*)&nladdr; - msg.msg_namelen = sizeof(nladdr); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + struct sockaddr_nl nladdr = { + .nl_family = AF_NETLINK + }; + + struct nlreq req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = TCPDIAG_GETSOCK, + /* NLM_F_ROOT: return the complete table instead of a single entry. + * NLM_F_MATCH: return all entries matching criteria (not implemented) + * NLM_F_REQUEST: must be set on all request messages */ + .nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST, + .nlh.nlmsg_pid = 0, + /* The sequence_number is used to track our messages. Since netlink is not + * reliable, we don't want to end up with a corrupt or incomplete old + * message in case the system is/was out of memory. */ + .nlh.nlmsg_seq = ++sequence_number, + .r.idiag_family = AF_INET, + .r.idiag_states = 0xfff, + .r.idiag_ext = 0 + }; + + struct iovec iov = { + .iov_base = &req, + .iov_len = sizeof(req) + }; + + struct msghdr msg = { + .msg_name = (void*)&nladdr, + .msg_namelen = sizeof(nladdr), + .msg_iov = &iov, + .msg_iovlen = 1 + }; if (sendmsg (fd, &msg, 0) < 0) { diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 638109ca..cf093c5f 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -198,7 +198,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) * Returns connected file objects or establishes the connection * if it's not already present */ - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_head; struct addrinfo *ai_ptr; int sd = -1; @@ -216,7 +216,6 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) } /* Get all addrs for this hostname */ - memset (&ai_hints, 0, sizeof (ai_hints)); #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -511,7 +510,7 @@ static int tss2_read_vserver (vserver_list_t *vserver) gauge_t packet_loss = NAN; int valid = 0; - char plugin_instance[DATA_MAX_NAME_LEN]; + char plugin_instance[DATA_MAX_NAME_LEN] = { 0 }; FILE *read_fh; FILE *write_fh; @@ -527,8 +526,6 @@ static int tss2_read_vserver (vserver_list_t *vserver) if (vserver == NULL) { /* Request global information */ - memset (plugin_instance, 0, sizeof (plugin_instance)); - status = tss2_send_request (write_fh, "gi\r\n"); } else diff --git a/src/ted.c b/src/ted.c index 186cf2b4..282212b1 100644 --- a/src/ted.c +++ b/src/ted.c @@ -74,7 +74,11 @@ static int ted_read_value(double *ret_power, double *ret_voltage) int package_buffer_pos; fd_set input; - struct timeval timeout; + + /* Initialize timeout structure, set to 2 seconds */ + struct timeval timeout = { + .tv_sec = 2 + }; int end_flag; int escape_flag; @@ -87,11 +91,6 @@ static int ted_read_value(double *ret_power, double *ret_voltage) FD_ZERO (&input); FD_SET (fd, &input); - /* Initialize timeout structure, set to 2 seconds */ - memset (&timeout, 0, sizeof (timeout)); - timeout.tv_sec = 2; - timeout.tv_usec = 0; - /* clear out anything in the buffer */ tcflush (fd, TCIFLUSH); diff --git a/src/threshold.c b/src/threshold.c index 77ba3f32..f12b4057 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -870,8 +870,6 @@ static int ut_config (oconfig_item_t *ci) int status = 0; int old_size = c_avl_size (threshold_tree); - threshold_t th; - if (threshold_tree == NULL) { threshold_tree = c_avl_create ((int (*) (const void *, const void *)) strcmp); @@ -882,15 +880,13 @@ static int ut_config (oconfig_item_t *ci) } } - memset (&th, '\0', sizeof (th)); - th.warning_min = NAN; - th.warning_max = NAN; - th.failure_min = NAN; - th.failure_max = NAN; - - th.hits = 0; - th.hysteresis = 0; - th.flags = UT_FLAG_INTERESTING; /* interesting by default */ + threshold_t th = { + .warning_min = NAN, + .warning_max = NAN, + .failure_min = NAN, + .failure_max = NAN, + .flags = UT_FLAG_INTERESTING /* interesting by default */ + }; for (i = 0; i < ci->children_num; i++) { diff --git a/src/unixsock.c b/src/unixsock.c index d4bf0047..5454fd8c 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -76,7 +76,7 @@ static pthread_t listen_thread = (pthread_t) 0; */ static int us_open_socket (void) { - struct sockaddr_un sa; + struct sockaddr_un sa = { 0 }; int status; sock_fd = socket (PF_UNIX, SOCK_STREAM, 0); @@ -88,7 +88,6 @@ static int us_open_socket (void) return (-1); } - memset (&sa, '\0', sizeof (sa)); sa.sun_family = AF_UNIX; sstrncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, sizeof (sa.sun_path)); diff --git a/src/uptime.c b/src/uptime.c index 345128da..4116b810 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -179,17 +179,13 @@ static int uptime_init (void) /* {{{ */ /* #endif HAVE_LIBKSTAT */ # elif HAVE_SYS_SYSCTL_H - struct timeval boottv; + struct timeval boottv = { 0 }; size_t boottv_len; int status; - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_BOOTTIME; + int mib[] = { CTL_KERN, KERN_BOOTTIME }; boottv_len = sizeof (boottv); - memset (&boottv, 0, boottv_len); status = sysctl (mib, STATIC_ARRAY_SIZE (mib), &boottv, &boottv_len, /* new_value = */ NULL, /* new_length = */ 0); diff --git a/src/utils_cmd_getthreshold.c b/src/utils_cmd_getthreshold.c index 80babe3e..7e4a9db1 100644 --- a/src/utils_cmd_getthreshold.c +++ b/src/utils_cmd_getthreshold.c @@ -53,7 +53,6 @@ int handle_getthreshold (FILE *fh, char *buffer) char *type; char *type_instance; - value_list_t vl; threshold_t threshold; int status; @@ -110,7 +109,9 @@ int handle_getthreshold (FILE *fh, char *buffer) return (-1); } - memset (&vl, 0, sizeof (vl)); + value_list_t vl = { + .values = NULL + }; sstrncpy (vl.host, host, sizeof (vl.host)); sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); if (plugin_instance != NULL) @@ -120,7 +121,6 @@ int handle_getthreshold (FILE *fh, char *buffer) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); sfree (identifier_copy); - memset (&threshold, 0, sizeof (threshold)); status = ut_search_threshold (&vl, &threshold); if (status == ENOENT) { diff --git a/src/utils_cmd_putnotif.c b/src/utils_cmd_putnotif.c index 145cd107..956ed745 100644 --- a/src/utils_cmd_putnotif.c +++ b/src/utils_cmd_putnotif.c @@ -119,7 +119,7 @@ static int set_option (notification_t *n, const char *option, const char *value) int handle_putnotif (FILE *fh, char *buffer) { char *command; - notification_t n; + notification_t n = { 0 }; int status; if ((fh == NULL) || (buffer == NULL)) @@ -143,8 +143,6 @@ int handle_putnotif (FILE *fh, char *buffer) return (-1); } - memset (&n, '\0', sizeof (n)); - status = 0; while (*buffer != 0) { diff --git a/src/utils_fbhash.c b/src/utils_fbhash.c index d1a580cd..d980f586 100644 --- a/src/utils_fbhash.c +++ b/src/utils_fbhash.c @@ -69,7 +69,7 @@ static int fbh_read_file (fbhash_t *h) /* {{{ */ { FILE *fh; char buffer[4096]; - struct flock fl; + struct flock fl = { 0 }; c_avl_tree_t *tree; int status; @@ -77,11 +77,8 @@ static int fbh_read_file (fbhash_t *h) /* {{{ */ if (fh == NULL) return (-1); - memset (&fl, 0, sizeof (fl)); fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; /* == entire file */ /* TODO: Lock file? -> fcntl */ status = fcntl (fileno (fh), F_SETLK, &fl); @@ -177,11 +174,9 @@ static int fbh_read_file (fbhash_t *h) /* {{{ */ static int fbh_check_file (fbhash_t *h) /* {{{ */ { - struct stat statbuf; + struct stat statbuf = { 0 }; int status; - memset (&statbuf, 0, sizeof (statbuf)); - status = stat (h->filename, &statbuf); if (status != 0) return (-1); diff --git a/src/utils_vl_lookup_test.c b/src/utils_vl_lookup_test.c index 2d541eea..668a8d0c 100644 --- a/src/utils_vl_lookup_test.c +++ b/src/utils_vl_lookup_test.c @@ -90,7 +90,6 @@ static int checked_lookup_add (lookup_t *obj, /* {{{ */ identifier_t ident; void *user_class; - memset (&ident, 0, sizeof (ident)); strncpy (ident.host, host, sizeof (ident.host)); strncpy (ident.plugin, plugin, sizeof (ident.plugin)); strncpy (ident.plugin_instance, plugin_instance, sizeof (ident.plugin_instance)); diff --git a/src/write_graphite.c b/src/write_graphite.c index 64794bec..25c7a637 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -193,7 +193,7 @@ static int wg_flush_nolock (cdtime_t timeout, struct wg_callback *cb) static int wg_callback_init (struct wg_callback *cb) { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list; struct addrinfo *ai_ptr; cdtime_t now; @@ -211,7 +211,6 @@ static int wg_callback_init (struct wg_callback *cb) return (EAGAIN); cb->last_connect_time = now; - memset (&ai_hints, 0, sizeof (ai_hints)); #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -406,7 +405,7 @@ static int wg_send_message (char const *message, struct wg_callback *cb) static int wg_write_messages (const data_set_t *ds, const value_list_t *vl, struct wg_callback *cb) { - char buffer[WG_SEND_BUF_SIZE]; + char buffer[WG_SEND_BUF_SIZE] = { 0 }; int status; if (0 != strcmp (ds->type, vl->type)) @@ -416,7 +415,6 @@ static int wg_write_messages (const data_set_t *ds, const value_list_t *vl, return -1; } - memset (buffer, 0, sizeof (buffer)); status = format_graphite (buffer, sizeof (buffer), ds, vl, cb->prefix, cb->postfix, cb->escape_char, cb->format_flags); if (status != 0) /* error message has been printed already. */ @@ -449,11 +447,9 @@ static int wg_write (const data_set_t *ds, const value_list_t *vl, static int config_set_char (char *dest, oconfig_item_t *ci) { - char buffer[4]; + char buffer[4] = { 0 }; int status; - memset (buffer, 0, sizeof (buffer)); - status = cf_util_get_string_buffer (ci, buffer, sizeof (buffer)); if (status != 0) return (status); @@ -480,7 +476,7 @@ static int config_set_char (char *dest, static int wg_config_node (oconfig_item_t *ci) { struct wg_callback *cb; - user_data_t user_data; + user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; int i; int status = 0; @@ -583,7 +579,6 @@ static int wg_config_node (oconfig_item_t *ci) ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s", cb->name); - memset (&user_data, 0, sizeof (user_data)); user_data.data = cb; user_data.free_func = wg_callback_free; plugin_register_write (callback_name, wg_write, &user_data); diff --git a/src/write_http.c b/src/write_http.c index 2d8e5535..3c2f7248 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -621,7 +621,7 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ { wh_callback_t *cb; int buffer_size = 0; - user_data_t user_data; + user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; int status = 0; int i; @@ -773,9 +773,7 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ DEBUG ("write_http: Registering write callback '%s' with URL '%s'", callback_name, cb->location); - memset (&user_data, 0, sizeof (user_data)); user_data.data = cb; - user_data.free_func = NULL; plugin_register_flush (callback_name, wh_flush, &user_data); user_data.free_func = wh_callback_free; diff --git a/src/write_log.c b/src/write_log.c index db09849f..25ff55e2 100644 --- a/src/write_log.c +++ b/src/write_log.c @@ -38,7 +38,7 @@ static int wl_write_messages (const data_set_t *ds, const value_list_t *vl) { - char buffer[WL_BUF_SIZE]; + char buffer[WL_BUF_SIZE] = { 0 }; int status; if (0 != strcmp (ds->type, vl->type)) @@ -48,7 +48,6 @@ static int wl_write_messages (const data_set_t *ds, const value_list_t *vl) return -1; } - memset (buffer, 0, sizeof (buffer)); status = format_graphite (buffer, sizeof (buffer), ds, vl, NULL, NULL, '_', 0); if (status != 0) /* error message has been printed already. */ diff --git a/src/write_redis.c b/src/write_redis.c index 5c299a48..4ec75d59 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -63,7 +63,7 @@ static int wr_write (const data_set_t *ds, /* {{{ */ wr_node_t *node = ud->data; char ident[512]; char key[512]; - char value[512]; + char value[512] = { 0 }; char time[24]; size_t value_size; char *value_ptr; @@ -78,7 +78,6 @@ static int wr_write (const data_set_t *ds, /* {{{ */ ident); ssnprintf (time, sizeof (time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time)); - memset (value, 0, sizeof (value)); value_size = sizeof (value); value_ptr = &value[0]; status = format_values (value_ptr, value_size, ds, vl, node->store_rates); diff --git a/src/write_tsdb.c b/src/write_tsdb.c index 2bd27072..a044b681 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -155,7 +155,7 @@ static int wt_flush_nolock(cdtime_t timeout, struct wt_callback *cb) static int wt_callback_init(struct wt_callback *cb) { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list; struct addrinfo *ai_ptr; int status; @@ -166,7 +166,6 @@ static int wt_callback_init(struct wt_callback *cb) if (cb->sock_fd > 0) return 0; - memset(&ai_hints, 0, sizeof(ai_hints)); #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -574,7 +573,7 @@ static int wt_write(const data_set_t *ds, const value_list_t *vl, static int wt_config_tsd(oconfig_item_t *ci) { struct wt_callback *cb; - user_data_t user_data; + user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; int i; @@ -617,7 +616,6 @@ static int wt_config_tsd(oconfig_item_t *ci) cb->node != NULL ? cb->node : WT_DEFAULT_NODE, cb->service != NULL ? cb->service : WT_DEFAULT_SERVICE); - memset(&user_data, 0, sizeof(user_data)); user_data.data = cb; user_data.free_func = wt_callback_free; plugin_register_write(callback_name, wt_write, &user_data); diff --git a/src/zookeeper.c b/src/zookeeper.c index 860e93d7..a236c8ae 100644 --- a/src/zookeeper.c +++ b/src/zookeeper.c @@ -105,13 +105,12 @@ static int zookeeper_connect (void) { int sk = -1; int status; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai; struct addrinfo *ai_list; const char *host; const char *port; - memset (&ai_hints, '\0', sizeof (ai_hints)); ai_hints.ai_family = AF_UNSPEC; ai_hints.ai_socktype = SOCK_STREAM;