X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fnetwork_parse.c;h=4c610bb0b7efe487dd5652eba6022479d058ffcb;hb=c4439c9cb3e2348ad7013644731de27a55eca478;hp=ce1bebccef90fee8a7e5eeac6d66abcf658cd489;hpb=969d1078bb7db51a81738711ff9623faa3cd6292;p=collectd.git diff --git a/src/libcollectdclient/network_parse.c b/src/libcollectdclient/network_parse.c index ce1bebcc..4c610bb0 100644 --- a/src/libcollectdclient/network_parse.c +++ b/src/libcollectdclient/network_parse.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -45,7 +46,7 @@ #elif HAVE_SYS_ENDIAN_H #include #else /* fallback */ -#include "stdendian.h" +#include "collectd/stdendian.h" #endif #if HAVE_GCRYPT_H @@ -68,7 +69,7 @@ static int network_parse(void *data, size_t data_size, lcc_security_level_t sl, lcc_network_parse_options_t const *opts); #if HAVE_GCRYPT_H -static int init_gcrypt() { +static int init_gcrypt(void) { /* 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 */ @@ -153,11 +154,12 @@ static int parse_string(void *payload, size_t payload_size, char *out, size_t out_size) { char *in = payload; - if ((payload_size < 1) || (in[payload_size - 1] != 0) || + if ((payload_size < 1) || (in[payload_size - 1] != '\0') || (payload_size > out_size)) return EINVAL; - strncpy(out, in, out_size); + strncpy(out, in, out_size - 1); + out[out_size - 1] = '\0'; return 0; } @@ -220,7 +222,7 @@ static int parse_time(uint16_t type, void *payload, size_t payload_size, static double ntohd(double val) /* {{{ */ { - static int config = 0; + static int config; union { uint8_t byte[8]; @@ -302,8 +304,8 @@ static int parse_values(void *payload, size_t payload_size, return EINVAL; state->values_len = (size_t)n; - state->values = calloc(sizeof(*state->values), state->values_len); - state->values_types = calloc(sizeof(*state->values_types), state->values_len); + state->values = calloc(state->values_len, sizeof(*state->values)); + state->values_types = calloc(state->values_len, sizeof(*state->values_types)); if ((state->values == NULL) || (state->values_types == NULL)) { return ENOMEM; }