From 36c7440c4015420568b7483ecdd78ad997af5ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Borb=C3=A9ly?= Date: Tue, 31 May 2016 15:22:45 +0200 Subject: [PATCH] Restore the previous way to convert strings in ecma_builtin_json_parse() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com --- .../ecma/builtin-objects/ecma-builtin-json.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c index a048f4ba1..ae3ac5188 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c @@ -706,13 +706,20 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg ecma_op_to_string (arg1), ret_value); - ecma_string_t *string_p = ecma_get_string_from_value (string); + const ecma_string_t *string_p = ecma_get_string_from_value (string); + const ecma_length_t string_size = (ecma_length_t) ecma_string_get_size (string_p); + const lit_utf8_size_t buffer_size = sizeof (lit_utf8_byte_t) * (string_size + 1); - ECMA_STRING_TO_UTF8_STRING (string_p, str_start_p, str_start_size); + JMEM_DEFINE_LOCAL_ARRAY (str_start_p, buffer_size, lit_utf8_byte_t); + + const lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p, str_start_p, buffer_size); + JERRY_ASSERT (sz == string_size); + + str_start_p[string_size] = LIT_BYTE_NULL; ecma_json_token_t token; - token.current_p = (lit_utf8_byte_t *) str_start_p; - token.end_p = str_start_p + str_start_size; + token.current_p = str_start_p; + token.end_p = str_start_p + string_size; ecma_value_t final_result = ecma_builtin_json_parse_value (&token); @@ -758,7 +765,7 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg } } - ECMA_FINALIZE_UTF8_STRING (str_start_p, str_start_size); + JMEM_FINALIZE_LOCAL_ARRAY (str_start_p); ECMA_FINALIZE (string); return ret_value;