Fix problems arising from incorrect use of various size types
E.g., * `ssize_t` was used where `lit_utf8_size_t` or `jerry_api_size_t` would have been correct, * `lit_utf8_size_t` was used where `ecma_length_t` would have been correct. Note, the patch also includes internal and public API changes: * `ecma_string_to_utf8_string` does not return negative value if output buffer is not large enough to contain the string; the buffer is expected to be large enough. (`ecma_string_get_size` can be used to retrieve the required size.) * `jerry_api_string_to_char_buffer` adapts the same logic (and `jerry_api_get_string_size` can be used to determine the required size of the buffer). Related issue: #942 JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -710,12 +710,12 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg
|
||||
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (string);
|
||||
ecma_length_t string_size = (uint32_t) ecma_string_get_size (string_p);
|
||||
size_t buffer_size = sizeof (lit_utf8_byte_t) * (string_size + 1);
|
||||
lit_utf8_size_t buffer_size = sizeof (lit_utf8_byte_t) * (string_size + 1);
|
||||
|
||||
MEM_DEFINE_LOCAL_ARRAY (str_start_p, buffer_size, lit_utf8_byte_t);
|
||||
|
||||
ssize_t sz = ecma_string_to_utf8_string (string_p, str_start_p, (ssize_t) buffer_size);
|
||||
JERRY_ASSERT (sz == (ssize_t) string_size);
|
||||
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;
|
||||
|
||||
@@ -1068,11 +1068,11 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
|
||||
|
||||
MEM_DEFINE_LOCAL_ARRAY (string_buff, string_size, lit_utf8_byte_t);
|
||||
|
||||
ssize_t bytes_copied = ecma_string_to_utf8_string (string_p,
|
||||
string_buff,
|
||||
(ssize_t) string_size);
|
||||
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string_p,
|
||||
string_buff,
|
||||
string_size);
|
||||
|
||||
JERRY_ASSERT (bytes_copied > 0 || !string_size);
|
||||
JERRY_ASSERT (bytes_copied == string_size);
|
||||
|
||||
lit_utf8_byte_t *str_p = string_buff;
|
||||
const lit_utf8_byte_t *str_end_p = str_p + string_size;
|
||||
|
||||
Reference in New Issue
Block a user