summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e1a7a8)
raw | patch | inline | side by side (parent: 0e1a7a8)
author | Florian Forster <octo@collectd.org> | |
Fri, 16 Mar 2012 17:26:08 +0000 (18:26 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 16 Mar 2012 17:26:08 +0000 (18:26 +0100) |
This hopefully avoids the annoying "trailing garbage" message when the buffer
only contains a newline or space at the end.
only contains a newline or space at the end.
src/common.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 530f73309327db8f0222acf2479e78799dfb8fcb..c5bd6470aa47e80564e5145312bfc9dec89b1500 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (0);
} /* int parse_identifier */
-int parse_value (const char *value, value_t *ret_value, int ds_type)
+int parse_value (const char *value_orig, value_t *ret_value, int ds_type)
{
+ char *value;
char *endptr = NULL;
+ size_t value_len;
+
+ if (value_orig == NULL)
+ return (EINVAL);
+
+ value = strdup (value_orig);
+ if (value == NULL)
+ return (ENOMEM);
+ value_len = strlen (value);
+
+ while ((value_len > 0) && isspace ((int) value[value_len - 1]))
+ {
+ value[value_len - 1] = 0;
+ value_len--;
+ }
switch (ds_type)
{
break;
default:
+ sfree (value);
ERROR ("parse_value: Invalid data source type: %i.", ds_type);
return -1;
}
if (value == endptr) {
+ sfree (value);
ERROR ("parse_value: Failed to parse string as %s: %s.",
DS_TYPE_TO_STRING (ds_type), value);
return -1;
else if ((NULL != endptr) && ('\0' != *endptr))
INFO ("parse_value: Ignoring trailing garbage \"%s\" after %s value. "
"Input string was \"%s\".",
- endptr, DS_TYPE_TO_STRING (ds_type), value);
+ endptr, DS_TYPE_TO_STRING (ds_type), value_orig);
+ sfree (value);
return 0;
} /* int parse_value */