mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 01:45:41 +02:00
Remember to check for missing commas
This commit is contained in:
+35
-11
@@ -75,19 +75,27 @@ static json_object *add_object(json_pull *j, json_type type) {
|
|||||||
|
|
||||||
if (c != NULL) {
|
if (c != NULL) {
|
||||||
if (c->type == JSON_ARRAY) {
|
if (c->type == JSON_ARRAY) {
|
||||||
if (SIZE_FOR(c->length + 1) != SIZE_FOR(c->length)) {
|
if (c->expect == JSON_ITEM) {
|
||||||
c->array = realloc(c->array, SIZE_FOR(c->length + 1) * sizeof(json_object *));
|
if (SIZE_FOR(c->length + 1) != SIZE_FOR(c->length)) {
|
||||||
}
|
c->array = realloc(c->array, SIZE_FOR(c->length + 1) * sizeof(json_object *));
|
||||||
|
}
|
||||||
|
|
||||||
c->array[c->length++] = o;
|
c->array[c->length++] = o;
|
||||||
c->expect = JSON_COMMA;
|
c->expect = JSON_COMMA;
|
||||||
|
} else {
|
||||||
|
j->error = "Expected a comma, not a list item";
|
||||||
|
free(c);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
} else if (c->type == JSON_HASH) {
|
} else if (c->type == JSON_HASH) {
|
||||||
if (c->expect == JSON_VALUE) {
|
if (c->expect == JSON_VALUE) {
|
||||||
c->values[c->length - 1] = o;
|
c->values[c->length - 1] = o;
|
||||||
c->expect = JSON_COMMA;
|
c->expect = JSON_COMMA;
|
||||||
} else {
|
} else if (c->expect == JSON_KEY) {
|
||||||
if (type != JSON_STRING) {
|
if (type != JSON_STRING) {
|
||||||
j->error = "Hash key is not a string";
|
j->error = "Hash key is not a string";
|
||||||
|
free(c);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SIZE_FOR(c->length + 1) != SIZE_FOR(c->length)) {
|
if (SIZE_FOR(c->length + 1) != SIZE_FOR(c->length)) {
|
||||||
@@ -99,6 +107,10 @@ static json_object *add_object(json_pull *j, json_type type) {
|
|||||||
c->values[c->length] = NULL;
|
c->values[c->length] = NULL;
|
||||||
c->length++;
|
c->length++;
|
||||||
c->expect = JSON_COLON;
|
c->expect = JSON_COLON;
|
||||||
|
} else {
|
||||||
|
j->error = "Expected a comma or colon";
|
||||||
|
free(c);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,7 +181,11 @@ again:
|
|||||||
/////////////////////////// Arrays
|
/////////////////////////// Arrays
|
||||||
|
|
||||||
if (c == '[') {
|
if (c == '[') {
|
||||||
j->container = add_object(j, JSON_ARRAY);
|
json_object *o = add_object(j, JSON_ARRAY);
|
||||||
|
if (o == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
j->container = o;
|
||||||
j->container->expect = JSON_ITEM;
|
j->container->expect = JSON_ITEM;
|
||||||
goto again;
|
goto again;
|
||||||
} else if (c == ']') {
|
} else if (c == ']') {
|
||||||
@@ -198,7 +214,11 @@ again:
|
|||||||
/////////////////////////// Hashes
|
/////////////////////////// Hashes
|
||||||
|
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
j->container = add_object(j, JSON_HASH);
|
json_object *o = add_object(j, JSON_HASH);
|
||||||
|
if (o == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
j->container = o;
|
||||||
j->container->expect = JSON_KEY;
|
j->container->expect = JSON_KEY;
|
||||||
goto again;
|
goto again;
|
||||||
} else if (c == '}') {
|
} else if (c == '}') {
|
||||||
@@ -350,7 +370,9 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
json_object *n = add_object(j, JSON_NUMBER);
|
json_object *n = add_object(j, JSON_NUMBER);
|
||||||
n->number = atof(val.buf);
|
if (n != NULL) {
|
||||||
|
n->number = atof(val.buf);
|
||||||
|
}
|
||||||
string_free(&val);
|
string_free(&val);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -410,8 +432,10 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
json_object *s = add_object(j, JSON_STRING);
|
json_object *s = add_object(j, JSON_STRING);
|
||||||
s->string = val.buf;
|
if (s != NULL) {
|
||||||
s->length = val.n;
|
s->string = val.buf;
|
||||||
|
s->length = val.n;
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user