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:
Akos Kiss
2016-03-07 19:08:57 +01:00
parent ce2fc3ccfd
commit 25b0750756
24 changed files with 228 additions and 331 deletions
@@ -88,8 +88,8 @@ ecma_builtin_global_object_print (ecma_value_t this_arg __attr_unused___, /**< t
utf8_str_size,
lit_utf8_byte_t);
ssize_t actual_sz = ecma_string_to_utf8_string (str_p, utf8_str_p, (ssize_t) utf8_str_size);
JERRY_ASSERT (actual_sz == (ssize_t) utf8_str_size);
lit_utf8_size_t actual_sz = ecma_string_to_utf8_string (str_p, utf8_str_p, utf8_str_size);
JERRY_ASSERT (actual_sz == utf8_str_size);
lit_utf8_byte_t *utf8_str_curr_p = utf8_str_p;
const lit_utf8_byte_t *utf8_str_end_p = utf8_str_p + utf8_str_size;
@@ -212,10 +212,10 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
{
MEM_DEFINE_LOCAL_ARRAY (string_buff, str_size, lit_utf8_byte_t);
ssize_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
string_buff,
(ssize_t) str_size);
JERRY_ASSERT (bytes_copied >= 0);
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
string_buff,
str_size);
JERRY_ASSERT (bytes_copied == str_size);
lit_utf8_byte_t *string_curr_p = string_buff;
lit_utf8_byte_t *string_end_p = string_buff + str_size;
@@ -437,10 +437,10 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
{
MEM_DEFINE_LOCAL_ARRAY (string_buff, str_size, lit_utf8_byte_t);
ssize_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
string_buff,
(ssize_t) str_size);
JERRY_ASSERT (bytes_copied >= 0);
lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
string_buff,
str_size);
JERRY_ASSERT (bytes_copied == str_size);
lit_utf8_byte_t *str_curr_p = string_buff;
lit_utf8_byte_t *str_end_p = string_buff + str_size;
@@ -771,10 +771,10 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
input_size + 1,
lit_utf8_byte_t);
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_size_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
input_size);
JERRY_ASSERT (sz == input_size);
input_start_p[input_size] = LIT_BYTE_NULL;
@@ -1049,10 +1049,10 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
input_size,
lit_utf8_byte_t);
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_size_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
input_size);
JERRY_ASSERT (sz == input_size);
/*
* The URI encoding has two major phases: first we validate the input,
@@ -1270,10 +1270,10 @@ ecma_builtin_global_object_escape (ecma_value_t this_arg __attr_unused___, /**<
input_size,
lit_utf8_byte_t);
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_size_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
input_size);
JERRY_ASSERT (sz == input_size);
/*
* The escape routine has two major phases: first we compute
@@ -1390,8 +1390,8 @@ ecma_builtin_global_object_unescape (ecma_value_t this_arg __attr_unused___, /**
/* 3. */
MEM_DEFINE_LOCAL_ARRAY (input_start_p, input_size, lit_utf8_byte_t);
ssize_t sz = ecma_string_to_utf8_string (input_string_p, input_start_p, (ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_size_t sz = ecma_string_to_utf8_string (input_string_p, input_start_p, input_size);
JERRY_ASSERT (sz == input_size);
lit_utf8_byte_t *input_curr_p = input_start_p;
lit_utf8_byte_t *input_end_p = input_start_p + input_size;