mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-04 17:35:42 +02:00
Clean up after errors and fix related bugs:
It was freeing the wrong object when there was an error attaching an object to its parent! Don't crash when printing null (partially read) hash values.
This commit is contained in:
@@ -52,7 +52,10 @@ void json_print_one(json_object *j, int *depth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void json_print(json_object *j, int depth) {
|
void json_print(json_object *j, int depth) {
|
||||||
if (j->type == JSON_HASH) {
|
if (j == NULL) {
|
||||||
|
// Hash value in incompletely read hash
|
||||||
|
printf("NULL");
|
||||||
|
} else if (j->type == JSON_HASH) {
|
||||||
printf("{\n");
|
printf("{\n");
|
||||||
indent(depth + 1);
|
indent(depth + 1);
|
||||||
|
|
||||||
@@ -123,7 +126,9 @@ void process_callback(FILE *f, char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jp->error != NULL) {
|
if (jp->error != NULL) {
|
||||||
|
fflush(stdout);
|
||||||
fprintf(stderr, "%s: %d: %s\n", fname, jp->line, jp->error);
|
fprintf(stderr, "%s: %d: %s\n", fname, jp->line, jp->error);
|
||||||
|
json_free(jp->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
json_end(jp);
|
json_end(jp);
|
||||||
|
|||||||
+8
-3
@@ -5,12 +5,15 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "jsonpull.h"
|
#include "jsonpull.h"
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
json_pull *json_begin(int (*read)(struct json_pull *), int (*peek)(struct json_pull *), void *source) {
|
json_pull *json_begin(int (*read)(struct json_pull *), int (*peek)(struct json_pull *), void *source) {
|
||||||
json_pull *j = malloc(sizeof(json_pull));
|
json_pull *j = malloc(sizeof(json_pull));
|
||||||
|
|
||||||
j->error = NULL;
|
j->error = NULL;
|
||||||
j->line = 1;
|
j->line = 1;
|
||||||
j->container = NULL;
|
j->container = NULL;
|
||||||
|
j->root = NULL;
|
||||||
|
|
||||||
j->read = read;
|
j->read = read;
|
||||||
j->peek = peek;
|
j->peek = peek;
|
||||||
@@ -97,7 +100,7 @@ static json_object *add_object(json_pull *j, json_type type) {
|
|||||||
c->expect = JSON_COMMA;
|
c->expect = JSON_COMMA;
|
||||||
} else {
|
} else {
|
||||||
j->error = "Expected a comma, not a list item";
|
j->error = "Expected a comma, not a list item";
|
||||||
free(c);
|
free(o);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (c->type == JSON_HASH) {
|
} else if (c->type == JSON_HASH) {
|
||||||
@@ -107,7 +110,7 @@ static json_object *add_object(json_pull *j, json_type type) {
|
|||||||
} else if (c->expect == JSON_KEY) {
|
} 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);
|
free(o);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,10 +125,12 @@ static json_object *add_object(json_pull *j, json_type type) {
|
|||||||
c->expect = JSON_COLON;
|
c->expect = JSON_COLON;
|
||||||
} else {
|
} else {
|
||||||
j->error = "Expected a comma or colon";
|
j->error = "Expected a comma or colon";
|
||||||
free(c);
|
free(o);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
j->root = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ typedef struct json_pull {
|
|||||||
void *source;
|
void *source;
|
||||||
|
|
||||||
json_object *container;
|
json_object *container;
|
||||||
|
json_object *root;
|
||||||
} json_pull;
|
} json_pull;
|
||||||
|
|
||||||
json_pull *json_begin_file(FILE *f);
|
json_pull *json_begin_file(FILE *f);
|
||||||
|
|||||||
Reference in New Issue
Block a user