From 285f1bf8e6a03fc109e7844f3842fa7f05f7dd73 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 5 Feb 2014 17:38:02 -0800 Subject: [PATCH] Fix number parsing bug and hash initialization bug --- json.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/json.c b/json.c index 824700a6..39ca15d2 100644 --- a/json.c +++ b/json.c @@ -52,6 +52,7 @@ static json_object *add_object(json_type type, json_object *parent) { json_hash *h = malloc(sizeof(json_hash)); h->next = parent->hash; h->key = o; + h->value = NULL; parent->hash = h; } } @@ -183,9 +184,15 @@ json_object *json_parse(FILE *f, json_object *current) { struct string val; string_init(&val); - string_append(&val, c); + if (c == '-') { + string_append(&val, c); + c = getc(f); + } - if (c >= '1' && c <= '9') { + if (c == '0') { + string_append(&val, c); + } else if (c >= '1' && c <= '9') { + string_append(&val, c); c = peek(f); while (c >= '0' && c <= '9') {