Skip to content

Commit 36c7440

Browse files
author
Zsolt Borbély
committed
Restore the previous way to convert strings in ecma_builtin_json_parse()
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
1 parent f24be95 commit 36c7440

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-json.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,20 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg
706706
ecma_op_to_string (arg1),
707707
ret_value);
708708

709-
ecma_string_t *string_p = ecma_get_string_from_value (string);
709+
const ecma_string_t *string_p = ecma_get_string_from_value (string);
710+
const ecma_length_t string_size = (ecma_length_t) ecma_string_get_size (string_p);
711+
const lit_utf8_size_t buffer_size = sizeof (lit_utf8_byte_t) * (string_size + 1);
710712

711-
ECMA_STRING_TO_UTF8_STRING (string_p, str_start_p, str_start_size);
713+
JMEM_DEFINE_LOCAL_ARRAY (str_start_p, buffer_size, lit_utf8_byte_t);
714+
715+
const lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p, str_start_p, buffer_size);
716+
JERRY_ASSERT (sz == string_size);
717+
718+
str_start_p[string_size] = LIT_BYTE_NULL;
712719

713720
ecma_json_token_t token;
714-
token.current_p = (lit_utf8_byte_t *) str_start_p;
715-
token.end_p = str_start_p + str_start_size;
721+
token.current_p = str_start_p;
722+
token.end_p = str_start_p + string_size;
716723

717724
ecma_value_t final_result = ecma_builtin_json_parse_value (&token);
718725

@@ -758,7 +765,7 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg
758765
}
759766
}
760767

761-
ECMA_FINALIZE_UTF8_STRING (str_start_p, str_start_size);
768+
JMEM_FINALIZE_LOCAL_ARRAY (str_start_p);
762769

763770
ECMA_FINALIZE (string);
764771
return ret_value;

0 commit comments

Comments
 (0)