From 727f612b382e9e914d9d03a00d770dee1c0c1195 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 25 Apr 2018 16:12:59 +0000 Subject: [PATCH] changed to null-terminate the intermediate token all the time in json.c --- lib/json.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/json.c b/lib/json.c index 72a3343..bcb2f8c 100644 --- a/lib/json.c +++ b/lib/json.c @@ -160,6 +160,7 @@ static HCL_INLINE int is_digitchar (hcl_ooci_t c) static void clear_token (hcl_json_t* json) { json->tok.len = 0; + if (json->tok_capa > 0) json->tok.ptr[json->tok.len] = '\0'; } static int add_char_to_token (hcl_json_t* json, hcl_ooch_t ch) @@ -178,6 +179,7 @@ static int add_char_to_token (hcl_json_t* json, hcl_ooch_t ch) } json->tok.ptr[json->tok.len++] = ch; + json->tok.ptr[json->tok.len] = '\0'; return 0; } @@ -275,7 +277,7 @@ static int invoke_data_inst (hcl_json_t* json, hcl_json_inst_t inst) inst = HCL_JSON_INST_KEY; } - if (json->prim.instcb (json, inst, &json->tok) <= -1) return -1; + if (json->prim.instcb(json, inst, &json->tok) <= -1) return -1; return 0; } @@ -542,14 +544,14 @@ static int handle_start_char (hcl_json_t* json, hcl_ooci_t c) { if (push_state(json, HCL_JSON_STATE_IN_ARRAY) <= -1) return -1; json->state_stack->u.ia.got_value = 0; - if (json->prim.instcb (json, HCL_JSON_INST_START_ARRAY, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_START_ARRAY, HCL_NULL) <= -1) return -1; return 1; } else if (c == '{') { if (push_state(json, HCL_JSON_STATE_IN_DIC) <= -1) return -1; json->state_stack->u.id.state = 0; - if (json->prim.instcb (json, HCL_JSON_INST_START_DIC, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_START_DIC, HCL_NULL) <= -1) return -1; return 1; } else if (is_spacechar(c)) @@ -568,7 +570,7 @@ static int handle_char_in_array (hcl_json_t* json, hcl_ooci_t c) { if (c == ']') { - if (json->prim.instcb (json, HCL_JSON_INST_END_ARRAY, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_END_ARRAY, HCL_NULL) <= -1) return -1; pop_state (json); return 1; } @@ -626,14 +628,14 @@ static int handle_char_in_array (hcl_json_t* json, hcl_ooci_t c) { if (push_state(json, HCL_JSON_STATE_IN_ARRAY) <= -1) return -1; json->state_stack->u.ia.got_value = 0; - if (json->prim.instcb (json, HCL_JSON_INST_START_ARRAY, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_START_ARRAY, HCL_NULL) <= -1) return -1; return 1; } else if (c == '{') { if (push_state(json, HCL_JSON_STATE_IN_DIC) <= -1) return -1; json->state_stack->u.id.state = 0; - if (json->prim.instcb (json, HCL_JSON_INST_START_DIC, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_START_DIC, HCL_NULL) <= -1) return -1; return 1; } else @@ -648,7 +650,7 @@ static int handle_char_in_dic (hcl_json_t* json, hcl_ooci_t c) { if (c == '}') { - if (json->prim.instcb (json, HCL_JSON_INST_END_DIC, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_END_DIC, HCL_NULL) <= -1) return -1; pop_state (json); return 1; } @@ -721,14 +723,14 @@ static int handle_char_in_dic (hcl_json_t* json, hcl_ooci_t c) { if (push_state(json, HCL_JSON_STATE_IN_ARRAY) <= -1) return -1; json->state_stack->u.ia.got_value = 0; - if (json->prim.instcb (json, HCL_JSON_INST_START_ARRAY, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_START_ARRAY, HCL_NULL) <= -1) return -1; return 1; } else if (c == '{') { if (push_state(json, HCL_JSON_STATE_IN_DIC) <= -1) return -1; json->state_stack->u.id.state = 0; - if (json->prim.instcb (json, HCL_JSON_INST_START_DIC, HCL_NULL) <= -1) return -1; + if (json->prim.instcb(json, HCL_JSON_INST_START_DIC, HCL_NULL) <= -1) return -1; return 1; } else