Add warn_unused_result attribute to ecma_string_to_utf8_string. Add assertions that specified buffer size is sufficient in places, where return value of ecma_string_to_utf8_string wasn't checked prior to the changes.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-08-27 17:12:26 +03:00
parent 6ee561e821
commit a26c454219
12 changed files with 99 additions and 52 deletions
@@ -208,7 +208,9 @@ ecma_builtin_date_parse (ecma_value_t this_arg __attr_unused___, /**< this argum
lit_utf8_size_t date_str_size = ecma_string_get_size (date_str_p);
MEM_DEFINE_LOCAL_ARRAY (date_start_p, date_str_size, lit_utf8_byte_t);
ecma_string_to_utf8_string (date_str_p, date_start_p, (ssize_t) date_str_size);
ssize_t sz = ecma_string_to_utf8_string (date_str_p, date_start_p, (ssize_t) date_str_size);
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t iter = lit_utf8_iterator_create (date_start_p, date_str_size);
/* 1. read year */
@@ -94,7 +94,9 @@ ecma_builtin_function_helper_get_arguments (const ecma_value_t *arguments_list_p
lit_utf8_size_t str_size = ecma_string_get_size (str_p);
MEM_DEFINE_LOCAL_ARRAY (start_p, str_size, lit_utf8_byte_t);
ecma_string_to_utf8_string (str_p, start_p, (ssize_t) str_size);
ssize_t sz = ecma_string_to_utf8_string (str_p, start_p, (ssize_t) str_size);
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t iter = lit_utf8_iterator_create (start_p, str_size);
while (!lit_utf8_iterator_is_eos (&iter))
@@ -190,7 +192,9 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
MEM_DEFINE_LOCAL_ARRAY (start_p, str_size, lit_utf8_byte_t);
ecma_string_to_utf8_string (arguments_str_p, start_p, (ssize_t) str_size);
ssize_t sz = ecma_string_to_utf8_string (arguments_str_p, start_p, (ssize_t) str_size);
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t iter = lit_utf8_iterator_create (start_p, str_size);
ecma_length_t last_separator = lit_utf8_iterator_get_index (&iter);
ecma_length_t end_position;
@@ -796,9 +796,11 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
input_size + 1,
lit_utf8_byte_t);
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
input_start_p[input_size] = LIT_BYTE_NULL;
lit_utf8_byte_t *input_char_p = input_start_p;
@@ -1043,9 +1045,10 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
input_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
/*
* The URI encoding has two major phases: first we validate the input,
@@ -1230,9 +1233,10 @@ ecma_builtin_global_object_escape (ecma_value_t this_arg __attr_unused___, /**<
input_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
/*
* The escape routine has two major phases: first we compute
@@ -593,9 +593,10 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
original_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (original_str_p,
original_str_utf8_p,
(ssize_t) (original_size));
ssize_t sz = ecma_string_to_utf8_string (original_str_p,
original_str_utf8_p,
(ssize_t) (original_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t original_it = lit_utf8_iterator_create (original_str_utf8_p, original_size);
@@ -607,9 +608,10 @@ ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**
search_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (search_str_p,
search_str_utf8_p,
(ssize_t) (search_size));
ssize_t sz = ecma_string_to_utf8_string (search_str_p,
search_str_utf8_p,
(ssize_t) (search_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t search_it = lit_utf8_iterator_create (search_str_utf8_p, search_size);
@@ -836,7 +836,9 @@ ecma_builtin_json_parse (ecma_value_t this_arg __attr_unused___, /**< 'this' arg
MEM_DEFINE_LOCAL_ARRAY (str_start_p, buffer_size, lit_utf8_byte_t);
ecma_string_to_utf8_string (string_p, str_start_p, (ssize_t) buffer_size);
ssize_t sz = ecma_string_to_utf8_string (string_p, str_start_p, (ssize_t) buffer_size);
JERRY_ASSERT (sz == (ssize_t) string_size);
str_start_p[string_size] = LIT_BYTE_NULL;
ecma_json_token_t token;
@@ -364,9 +364,10 @@ ecma_builtin_string_prototype_object_index_of (ecma_value_t this_arg, /**< this
original_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (original_str_p,
original_str_utf8_p,
(ssize_t) (original_size));
ssize_t sz = ecma_string_to_utf8_string (original_str_p,
original_str_utf8_p,
(ssize_t) (original_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t original_it = lit_utf8_iterator_create (original_str_utf8_p, original_size);
@@ -378,9 +379,10 @@ ecma_builtin_string_prototype_object_index_of (ecma_value_t this_arg, /**< this
search_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (search_str_p,
search_str_utf8_p,
(ssize_t) (search_size));
ssize_t sz = ecma_string_to_utf8_string (search_str_p,
search_str_utf8_p,
(ssize_t) (search_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t search_it = lit_utf8_iterator_create (search_str_utf8_p, search_size);
@@ -888,9 +890,10 @@ ecma_builtin_string_prototype_object_replace_match (ecma_builtin_replace_search_
search_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (search_string_p,
search_start_p,
(ssize_t) (search_size));
ssize_t sz = ecma_string_to_utf8_string (search_string_p,
search_start_p,
(ssize_t) (search_size));
JERRY_ASSERT (sz >= 0);
ecma_string_t *input_string_p = ecma_get_string_from_value (context_p->input_string);
lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);
@@ -899,9 +902,10 @@ ecma_builtin_string_prototype_object_replace_match (ecma_builtin_replace_search_
input_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
lit_utf8_iterator_t search_iterator = lit_utf8_iterator_create (search_start_p, search_size);
lit_utf8_iterator_t input_iterator = lit_utf8_iterator_create (input_start_p, input_size);
@@ -1409,9 +1413,10 @@ ecma_builtin_string_prototype_object_replace_main (ecma_builtin_replace_search_c
replace_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (replace_string_p,
replace_start_p,
(ssize_t) (replace_size));
ssize_t sz = ecma_string_to_utf8_string (replace_string_p,
replace_start_p,
(ssize_t) (replace_size));
JERRY_ASSERT (sz >= 0);
context_p->replace_string_p = replace_string_p;
context_p->replace_iterator = lit_utf8_iterator_create (replace_start_p, replace_size);
@@ -2284,9 +2289,10 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_value_t this_arg, /
input_size,
lit_utf8_byte_t);
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
ssize_t sz = ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
JERRY_ASSERT (sz >= 0);
/*
* The URI encoding has two major phases: first we compute
@@ -2503,7 +2509,8 @@ ecma_builtin_string_prototype_object_trim (ecma_value_t this_arg) /**< this argu
/* Workaround: avoid repeated call of ecma_string_get_char_at_pos() because its overhead */
lit_utf8_byte_t *original_utf8_str_p = (lit_utf8_byte_t *) mem_heap_alloc_block (size + 1,
MEM_HEAP_ALLOC_SHORT_TERM);
ecma_string_to_utf8_string (original_string_p, original_utf8_str_p, (ssize_t) size);
ssize_t sz = ecma_string_to_utf8_string (original_string_p, original_utf8_str_p, (ssize_t) size);
JERRY_ASSERT (sz >= 0);
const ecma_length_t length = lit_utf8_string_length (original_utf8_str_p, size);