diff --git a/src/write_graphite.c b/src/write_graphite.c index 6b16bec..68d264e 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -351,22 +351,25 @@ static void wg_copy_escape_part (char *dst, const char *src, size_t dst_len, { size_t i; - memset (dst, 0, dst_len); - if (src == NULL) + { + dst[0] = 0; return; + } for (i = 0; i < dst_len; i++) { - if ((src[i] == '.') + if (src[i] == 0) + { + dst[i] = '\0'; + break; + } + else if ((src[i] == '.') || isspace ((int) src[i]) || iscntrl ((int) src[i])) dst[i] = escape_char; else dst[i] = src[i]; - - if (src[i] == 0) - break; } } @@ -387,7 +390,6 @@ static int wg_format_name (char *ret, int ret_len, assert (hostname != NULL); assert (plugin != NULL); assert (type != NULL); - assert (ds_name != NULL); if (prefix == NULL) prefix = ""; @@ -410,34 +412,44 @@ static int wg_format_name (char *ret, int ret_len, { if (n_type_instance[0] == '\0') { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s", - prefix, n_hostname, postfix, n_plugin, n_type, ds_name); + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s", + prefix, n_hostname, postfix, n_plugin, n_type); } else { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s", prefix, n_hostname, postfix, n_plugin, n_type, - n_type_instance, ds_name); + n_type_instance); } } else { if (n_type_instance[0] == '\0') { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s", prefix, n_hostname, postfix, n_plugin, - n_plugin_instance, n_type, ds_name); + n_plugin_instance, n_type); } else { - status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s", prefix, n_hostname, postfix, n_plugin, - n_plugin_instance, n_type, n_type_instance, ds_name); + n_plugin_instance, n_type, n_type_instance); } } if ((status < 1) || (status >= ret_len)) return (-1); + + if( ds_name ) + { + int ret_remaining = ret_len - status; + + status = ssnprintf( ret + status, ret_remaining, ".%s", ds_name ); + + if ((status < 1) || (status >= ret_remaining)) + return (-1); + } return (0); }