summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0f4dc42)
raw | patch | inline | side by side (parent: 0f4dc42)
author | Florian Forster <octo@collectd.org> | |
Tue, 2 Sep 2014 17:49:11 +0000 (19:49 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Tue, 2 Sep 2014 17:49:14 +0000 (19:49 +0200) |
Previously, `meta != NULL` and `keys_num == 0` was possible and would
result in "{}", which is not valid JSON.
Fixes: 716
result in "{}", which is not valid JSON.
Fixes: 716
src/utils_format_json.c | patch | blob | history |
index bbc3dfdb4efc9b21be341e2e1ff2845c67e5ed33..898b1725eac821acc99407c09061661abbeabca7 100644 (file)
--- a/src/utils_format_json.c
+++ b/src/utils_format_json.c
int status;
int i;
- memset (buffer, 0, buffer_size);
+ buffer[0] = 0;
+
+ if (meta == NULL)
+ return (EINVAL);
#define BUFFER_ADD(...) do { \
status = ssnprintf (buffer + offset, buffer_size - offset, \
} while (0)
keys_num = meta_data_toc (meta, &keys);
+ if (keys_num == 0)
+ {
+ sfree (keys);
+ return (0);
+ }
+
for (i = 0; i < keys_num; ++i)
{
int type;
#undef BUFFER_ADD
return (0);
-} /* int meta_data_to_json */
+} /* }}} int meta_data_to_json */
static int value_list_to_json (char *buffer, size_t buffer_size, /* {{{ */
const data_set_t *ds, const value_list_t *vl, int store_rates)