X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils%2Fformat_graphite%2Fformat_graphite.c;h=ffef3e2f626d9b27b57a58b4e6a4bd9f4772bd9d;hb=dfb17826ceb8223cca9009b7b9f4194252ff994d;hp=55823566f7ec9c5df241289880b81b6491ab6a35;hpb=7045c4b543304ffabaa30a2ca9183489e75eafe3;p=collectd.git diff --git a/src/utils/format_graphite/format_graphite.c b/src/utils/format_graphite/format_graphite.c index 55823566..ffef3e2f 100644 --- a/src/utils/format_graphite/format_graphite.c +++ b/src/utils/format_graphite/format_graphite.c @@ -36,10 +36,8 @@ /* helper function for reverse_hostname */ void reverse_string(char *r_host, int len) { - char t; - for (int i = 0; i < len / 2; i++) { - int j = len - i - 1; - t = r_host[i]; + for (int i = 0, j = len - 1; i < j; i++, j--) { + char t = r_host[i]; r_host[i] = r_host[j]; r_host[j] = t; } @@ -152,8 +150,7 @@ static int gr_format_name_tagged(char *ret, int ret_len, value_list_t const *vl, postfix = ""; if (flags & GRAPHITE_REVERSE_HOST) { - int len_host = strlen(vl->host); - char r_host[len_host + 1]; + char r_host[DATA_MAX_NAME_LEN]; reverse_hostname(r_host, vl->host); gr_copy_escape_part(n_host, r_host, sizeof(n_host), escape_char, 1); } else { @@ -237,8 +234,7 @@ static int gr_format_name(char *ret, int ret_len, value_list_t const *vl, bool preserve_separator = (flags & GRAPHITE_PRESERVE_SEPARATOR); if (flags & GRAPHITE_REVERSE_HOST) { - int len_host = strlen(vl->host); - char r_host[len_host + 1]; + char r_host[DATA_MAX_NAME_LEN]; reverse_hostname(r_host, vl->host); gr_copy_escape_part(n_host, r_host, sizeof(n_host), escape_char, preserve_separator);