X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fntpd.c;h=f7b57ba30ce30ecc3c7826f879d2d4bb99629028;hb=3fae5596643f1e361eb18c3d65448f8bc02fdd80;hp=f8f4f04974bc2f241554d023e5687a8d458d0d4b;hpb=e0a35d57e56ec31e42b1aa984cb2038f570925e6;p=collectd.git 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,