Merge pull request #1806 from rubenk/network-plugin-size_t
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Wed, 27 Jul 2016 12:42:46 +0000 (14:42 +0200)
committerGitHub <noreply@github.com>
Wed, 27 Jul 2016 12:42:46 +0000 (14:42 +0200)
network plugin: use size_t for length and offsets

1  2 
src/network.c

diff --combined src/network.c
@@@ -30,6 -30,7 +30,6 @@@
  #include "common.h"
  #include "configfile.h"
  #include "utils_fbhash.h"
 -#include "utils_avltree.h"
  #include "utils_cache.h"
  #include "utils_complain.h"
  
@@@ -493,8 -494,6 +493,8 @@@ static int network_dispatch_notificatio
  #if HAVE_LIBGCRYPT
  static void network_init_gcrypt (void) /* {{{ */
  {
 +  gcry_error_t err;
 +
    /* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
     * Because you can't know in a library whether another library has
     * already initialized the library */
    *
    * tl;dr: keep all these gry_* statements in this exact order please. */
  # if GCRYPT_VERSION_NUMBER < 0x010600
 -  gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
 +  err = gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
 +  if (err)
 +  {
 +    ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err));
 +    abort ();
 +  }
  # endif
 +
    gcry_check_version (NULL);
 -  gcry_control (GCRYCTL_INIT_SECMEM, 32768);
 +
 +  err = gcry_control (GCRYCTL_INIT_SECMEM, 32768);
 +  if (err)
 +  {
 +    ERROR ("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s", gcry_strerror (err));
 +    abort ();
 +  }
 +
    gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
  } /* }}} void network_init_gcrypt */
  
@@@ -605,11 -591,11 +605,11 @@@ static gcry_cipher_hd_t network_get_aes
  } /* }}} int network_get_aes256_cypher */
  #endif /* HAVE_LIBGCRYPT */
  
- static int write_part_values (char **ret_buffer, int *ret_buffer_len,
+ static int write_part_values (char **ret_buffer, size_t *ret_buffer_len,
                const data_set_t *ds, const value_list_t *vl)
  {
        char *packet_ptr;
-       int packet_len;
+       size_t packet_len;
        int num_values;
  
        part_header_t pkg_ph;
        uint8_t      *pkg_values_types;
        value_t      *pkg_values;
  
-       int offset;
+       size_t offset;
        int i;
  
        num_values = vl->values_len;
        return (0);
  } /* int write_part_values */
  
- static int write_part_number (char **ret_buffer, int *ret_buffer_len,
+ static int write_part_number (char **ret_buffer, size_t *ret_buffer_len,
                int type, uint64_t value)
  {
        char *packet_ptr;
-       int packet_len;
+       size_t packet_len;
  
        part_header_t pkg_head;
        uint64_t pkg_value;
  
-       int offset;
+       size_t offset;
  
        packet_len = sizeof (pkg_head) + sizeof (pkg_value);
  
        return (0);
  } /* int write_part_number */
  
- static int write_part_string (char **ret_buffer, int *ret_buffer_len,
-               int type, const char *str, int str_len)
+ static int write_part_string (char **ret_buffer, size_t *ret_buffer_len,
+               int type, const char *str, size_t str_len)
  {
        char *buffer;
-       int buffer_len;
+       size_t buffer_len;
  
        uint16_t pkg_type;
        uint16_t pkg_length;
  
-       int offset;
+       size_t offset;
  
        buffer_len = 2 * sizeof (uint16_t) + str_len + 1;
        if (*ret_buffer_len < buffer_len)
@@@ -2814,7 -2800,7 +2814,7 @@@ static void network_send_buffer (char *
    } /* for (sending_sockets) */
  } /* }}} void network_send_buffer */
  
- static int add_to_buffer (char *buffer, int buffer_size, /* {{{ */
+ static int add_to_buffer (char *buffer, size_t buffer_size, /* {{{ */
                value_list_t *vl_def,
                const data_set_t *ds, const value_list_t *vl)
  {
@@@ -3258,10 -3244,10 +3258,10 @@@ static int network_config (oconfig_item
  static int network_notification (const notification_t *n,
      user_data_t __attribute__((unused)) *user_data)
  {
-   char  buffer[network_config_packet_size];
-   char *buffer_ptr = buffer;
-   int   buffer_free = sizeof (buffer);
-   int   status;
+   char   buffer[network_config_packet_size];
+   char  *buffer_ptr = buffer;
+   size_t buffer_free = sizeof (buffer);
+   int    status;
  
    if (!check_send_notify_okay (n))
      return (0);