be a bit more strict: check if in object when specifying member - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit c6b45090c8319714795a2024a1282a3273f08101
(DIR) parent 78022f6392717c91ae58c1cef069c776c2b2e5e3
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sat, 5 Oct 2019 12:51:46 +0200
be a bit more strict: check if in object when specifying member
and add a newlines to a fatal() error messages
Diffstat:
M json2tsv.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/json2tsv.c b/json2tsv.c
@@ -88,13 +88,13 @@ capacity(char **value, size_t *sz, size_t cur, size_t inc)
/* check addition overflow */
need = cur + inc;
if (cur > SIZE_MAX - need || *sz > SIZE_MAX - 16384)
- fatal("overflow");
+ fatal("overflow\n");
if (*sz == 0 || need > *sz) {
for (newsiz = *sz; newsiz < need; newsiz += 16384)
;
if (!(*value = realloc(*value, newsiz)))
- fatal("realloc");
+ fatal("realloc\n");
*sz = newsiz;
}
}
@@ -119,6 +119,8 @@ parsejson(void (*cb)(struct json_node *, size_t, const char *))
case ':':
nodes[depth].type = TYPE_PRIMITIVE;
if (v) {
+ if (!depth || nodes[depth - 1].type != TYPE_OBJECT)
+ fatal("object member, but not in an object\n");
value[v] = '\0';
capacity(&(nodes[depth].name), &(nodes[depth].namesiz), v, 1);
memcpy(nodes[depth].name, value, v);