Merge branch 'collectd-5.5' into collectd-5.6
[collectd.git] / src / libcollectdclient / network_buffer.c
index 8d35d20..2c6277c 100644 (file)
@@ -36,7 +36,6 @@
 #include <pthread.h>
 
 #if HAVE_LIBGCRYPT
-# include <pthread.h>
 # if defined __APPLE__
 /* default xcode compiler throws warnings even when deprecated functionality
  * is not used. -Werror breaks the build because of erroneous warnings.
@@ -275,7 +274,6 @@ static int nb_add_values (char **ret_buffer, /* {{{ */
   value_t       pkg_values[vl->values_len];
 
   size_t offset;
-  size_t i;
 
   packet_len = sizeof (pkg_type) + sizeof (pkg_length)
     + sizeof (pkg_num_values)
@@ -289,7 +287,7 @@ static int nb_add_values (char **ret_buffer, /* {{{ */
   pkg_length = htons ((uint16_t) packet_len);
   pkg_num_values = htons ((uint16_t) vl->values_len);
 
-  for (i = 0; i < vl->values_len; i++)
+  for (size_t i = 0; i < vl->values_len; i++)
   {
     pkg_values_types[i] = (uint8_t) vl->values_types[i];
     switch (vl->values_types[i])
@@ -654,19 +652,17 @@ lcc_network_buffer_t *lcc_network_buffer_create (size_t size) /* {{{ */
     return (NULL);
   }
 
-  nb = malloc (sizeof (*nb));
+  nb = calloc (1, sizeof (*nb));
   if (nb == NULL)
     return (NULL);
-  memset (nb, 0, sizeof (*nb));
 
   nb->size = size;
-  nb->buffer = malloc (nb->size);
+  nb->buffer = calloc (1, nb->size);
   if (nb->buffer == NULL)
   {
     free (nb);
     return (NULL);
   }
-  memset (nb->buffer, 0, nb->size);
 
   nb->ptr = nb->buffer;
   nb->free = nb->size;
@@ -764,7 +760,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;
@@ -772,9 +769,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);