fix: segfalt in json_get_object_item
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "chectic.h"
|
||||
#include "cjson/cJSON.h"
|
||||
#include "hmpl.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -11,14 +10,12 @@ int main(int argc, char *argv[]) {
|
||||
raise_info("start");
|
||||
|
||||
Arena arena = arena_init(1024 * 1024);
|
||||
Arena arena_for_jsons = arena_init(1024 * 1024);
|
||||
init_cjson_with_arenas(&arena_for_jsons);
|
||||
|
||||
raise_info("read the arguments");
|
||||
char *text = NULL;
|
||||
|
||||
const char *json_input = (argc > 1 ? argv[1] : "{}");
|
||||
cJSON *context = cJSON_Parse(json_input);
|
||||
Json *context = json_parse(&arena, &json_input);
|
||||
|
||||
if (!context) {
|
||||
fprintf(stderr, "Error parsing JSON\n");
|
||||
@@ -33,7 +30,6 @@ int main(int argc, char *argv[]) {
|
||||
ssize_t len = getdelim(&heap_text, &size, '\0', stdin);
|
||||
if (len < 0) {
|
||||
perror("read stdin");
|
||||
cJSON_Delete(context);
|
||||
return 1;
|
||||
}
|
||||
text = arena_strdup(&arena, heap_text);
|
||||
@@ -46,6 +42,5 @@ int main(int argc, char *argv[]) {
|
||||
printf("%s", text);
|
||||
|
||||
arena_free(&arena);
|
||||
cJSON_Delete(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user