From: Florian Forster Date: Fri, 18 Dec 2015 08:26:14 +0000 (+0100) Subject: network plugin: Coding style fixes. X-Git-Tag: collectd-5.6.0~482 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0092ac0b35a2fd05fa21c0be5f82aea1a5c3ebe7;p=collectd.git network plugin: Coding style fixes. This fixes a number of sizeof() operations which did not follow our best practice of using the variable rather than its type. It also removes unnecessary (void *) casts. --- diff --git a/src/network.c b/src/network.c index f44fe621..439b0cef 100644 --- a/src/network.c +++ b/src/network.c @@ -776,11 +776,11 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, uint16_t tmp16; size_t exp_size; - int i; + size_t i; uint16_t pkg_length; uint16_t pkg_type; - uint16_t pkg_numval; + size_t pkg_numval; uint8_t *pkg_types; value_t *pkg_values; @@ -802,7 +802,7 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); - pkg_numval = ntohs (tmp16); + pkg_numval = (size_t) ntohs (tmp16); assert (pkg_type == TYPE_VALUES); @@ -827,20 +827,20 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, return (-1); } - pkg_types = (uint8_t *) malloc (pkg_numval * sizeof (uint8_t)); - pkg_values = (value_t *) malloc (pkg_numval * sizeof (value_t)); + pkg_types = calloc (pkg_numval, sizeof (*pkg_types)); + pkg_values = calloc (pkg_numval, sizeof (*pkg_values)); if ((pkg_types == NULL) || (pkg_values == NULL)) { sfree (pkg_types); sfree (pkg_values); - ERROR ("network plugin: parse_part_values: malloc failed."); + ERROR ("network plugin: parse_part_values: calloc failed."); return (-1); } - memcpy ((void *) pkg_types, (void *) buffer, pkg_numval * sizeof (uint8_t)); - buffer += pkg_numval * sizeof (uint8_t); - memcpy ((void *) pkg_values, (void *) buffer, pkg_numval * sizeof (value_t)); - buffer += pkg_numval * sizeof (value_t); + memcpy (pkg_types, buffer, pkg_numval * sizeof (*pkg_types)); + buffer += pkg_numval * sizeof (*pkg_types); + memcpy (pkg_values, buffer, pkg_numval * sizeof (*pkg_values)); + buffer += pkg_numval * sizeof (*pkg_values); for (i = 0; i < pkg_numval; i++) { @@ -874,7 +874,7 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, *ret_buffer = buffer; *ret_buffer_len = buffer_len - pkg_length; - *ret_num_values = (size_t) pkg_numval; + *ret_num_values = pkg_numval; *ret_values = pkg_values; sfree (pkg_types);