summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2f0eb44)
raw | patch | inline | side by side (parent: 2f0eb44)
author | Florian Forster <octo@collectd.org> | |
Fri, 18 Dec 2015 08:26:14 +0000 (09:26 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 18 Dec 2015 08:26:14 +0000 (09:26 +0100) |
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.
practice of using the variable rather than its type. It also removes
unnecessary (void *) casts.
src/network.c | patch | blob | history |
diff --git a/src/network.c b/src/network.c
index f44fe621c1717a16ab0d5a2dbb236e89397a3cf2..439b0cef704d7d22404f73561faf4d2b3241729c 100644 (file)
--- a/src/network.c
+++ b/src/network.c
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;
memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
buffer += sizeof (tmp16);
- pkg_numval = ntohs (tmp16);
+ pkg_numval = (size_t) ntohs (tmp16);
assert (pkg_type == TYPE_VALUES);
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++)
{
*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);