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:
@@ -353,10 +353,10 @@ lit_char_is_word_char (ecma_char_t c) /**< code unit */
|
||||
* @return the length of the lowercase character sequence
|
||||
* which is always between 1 and LIT_MAXIMUM_OTHER_CASE_LENGTH.
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_length_t
|
||||
lit_char_to_lower_case (ecma_char_t character, /**< input character value */
|
||||
ecma_char_t *output_buffer_p, /**< [out] buffer for the result characters */
|
||||
size_t buffer_size) /**< buffer size */
|
||||
ecma_length_t buffer_size) /**< buffer size */
|
||||
{
|
||||
TODO ("Needs a proper lower case implementation. See issue #323.");
|
||||
|
||||
@@ -387,10 +387,10 @@ lit_char_to_lower_case (ecma_char_t character, /**< input character value */
|
||||
* @return the length of the uppercase character sequence
|
||||
* which is always between 1 and LIT_MAXIMUM_OTHER_CASE_LENGTH.
|
||||
*/
|
||||
lit_utf8_size_t
|
||||
ecma_length_t
|
||||
lit_char_to_upper_case (ecma_char_t character, /**< input character value */
|
||||
ecma_char_t *output_buffer_p, /**< buffer for the result characters */
|
||||
size_t buffer_size) /**< buffer size */
|
||||
ecma_length_t buffer_size) /**< buffer size */
|
||||
{
|
||||
TODO ("Needs a proper upper case implementation. See issue #323.");
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ extern bool lit_char_is_word_char (ecma_char_t);
|
||||
*/
|
||||
#define LIT_MAXIMUM_OTHER_CASE_LENGTH (3)
|
||||
|
||||
lit_utf8_size_t lit_char_to_lower_case (ecma_char_t, ecma_char_t *, size_t);
|
||||
lit_utf8_size_t lit_char_to_upper_case (ecma_char_t, ecma_char_t *, size_t);
|
||||
ecma_length_t lit_char_to_lower_case (ecma_char_t, ecma_char_t *, ecma_length_t);
|
||||
ecma_length_t lit_char_to_upper_case (ecma_char_t, ecma_char_t *, ecma_length_t);
|
||||
|
||||
#endif /* LIT_CHAR_HELPERS_H */
|
||||
|
||||
@@ -520,63 +520,6 @@ lit_literal_equal_type (lit_literal_t lit1, /**< first literal */
|
||||
return lit_literal_equal (lit1, lit2);
|
||||
} /* lit_literal_equal_type */
|
||||
|
||||
/**
|
||||
* Get the contents of the literal as a zero-terminated string.
|
||||
* If literal is a magic string record, the corresponding string is not copied to the buffer,
|
||||
* but is returned directly.
|
||||
*
|
||||
* @return pointer to the zero-terminated string.
|
||||
*/
|
||||
const lit_utf8_byte_t *
|
||||
lit_literal_to_utf8_string (lit_literal_t lit, /**< literal to be processed */
|
||||
lit_utf8_byte_t *buff_p, /**< buffer to use as a string storage */
|
||||
size_t size) /**< size of the buffer */
|
||||
{
|
||||
JERRY_ASSERT (buff_p != NULL && size > 0);
|
||||
|
||||
switch (lit->type)
|
||||
{
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
const size_t str_size = lit_charset_literal_get_size (lit);
|
||||
memcpy (buff_p, lit_charset_literal_get_charset (lit), (size > str_size) ? str_size : size);
|
||||
return buff_p;
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
return lit_get_magic_string_utf8 (lit_magic_literal_get_magic_str_id (lit));
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
return lit_get_magic_string_ex_utf8 (lit_magic_literal_get_magic_str_ex_id (lit));
|
||||
}
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t number = lit_number_literal_get_number (lit);
|
||||
ecma_number_to_utf8_string (number, buff_p, (ssize_t) size);
|
||||
return buff_p;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* lit_literal_to_utf8_string */
|
||||
|
||||
/**
|
||||
* Get the contents of the literal as a C string.
|
||||
* If literal holds a very long string, it would be trimmed to ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER characters.
|
||||
*
|
||||
* @return pointer to the C string.
|
||||
*/
|
||||
const char *
|
||||
lit_literal_to_str_internal_buf (lit_literal_t lit) /**< literal */
|
||||
{
|
||||
static lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1];
|
||||
memset (buff, 0, sizeof (buff));
|
||||
|
||||
return (const char *) lit_literal_to_utf8_string (lit, buff, sizeof (buff) - 1);
|
||||
} /* lit_literal_to_str_internal_buf */
|
||||
|
||||
|
||||
/**
|
||||
* Check if literal really exists in the storage
|
||||
*
|
||||
|
||||
@@ -49,9 +49,6 @@ extern bool lit_literal_equal_type_num (lit_literal_t, ecma_number_t);
|
||||
extern bool lit_literal_equal_type (lit_literal_t, lit_literal_t);
|
||||
extern bool lit_literal_equal_charset (lit_literal_t, const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
|
||||
extern const lit_utf8_byte_t *lit_literal_to_utf8_string (lit_literal_t, lit_utf8_byte_t *, size_t);
|
||||
extern const char *lit_literal_to_str_internal_buf (lit_literal_t);
|
||||
|
||||
extern lit_literal_t lit_get_literal_by_cp (lit_cpointer_t);
|
||||
|
||||
extern ecma_number_t lit_number_literal_get_number (lit_literal_t);
|
||||
|
||||
@@ -257,14 +257,14 @@ lit_compare_utf8_string_and_magic_string_ex (const lit_utf8_byte_t *string_p, /*
|
||||
extern lit_utf8_byte_t *
|
||||
lit_copy_magic_string_to_buffer (lit_magic_string_id_t id, /**< magic string id */
|
||||
lit_utf8_byte_t *buffer_p, /**< destination buffer */
|
||||
ssize_t buffer_size) /**< size of buffer */
|
||||
lit_utf8_size_t buffer_size) /**< size of buffer */
|
||||
{
|
||||
const lit_utf8_byte_t *magic_string_bytes_p = lit_get_magic_string_utf8 (id);
|
||||
lit_utf8_size_t magic_string_bytes_count = lit_get_magic_string_size (id);
|
||||
|
||||
const lit_utf8_byte_t *str_iter_p = magic_string_bytes_p;
|
||||
lit_utf8_byte_t *buf_iter_p = buffer_p;
|
||||
ssize_t bytes_copied = 0;
|
||||
lit_utf8_size_t bytes_copied = 0;
|
||||
|
||||
while (magic_string_bytes_count--)
|
||||
{
|
||||
|
||||
@@ -62,6 +62,6 @@ extern bool lit_compare_utf8_string_and_magic_string (const lit_utf8_byte_t *, l
|
||||
extern bool lit_compare_utf8_string_and_magic_string_ex (const lit_utf8_byte_t *, lit_utf8_size_t,
|
||||
lit_magic_string_ex_id_t);
|
||||
|
||||
extern lit_utf8_byte_t *lit_copy_magic_string_to_buffer (lit_magic_string_id_t, lit_utf8_byte_t *, ssize_t);
|
||||
extern lit_utf8_byte_t *lit_copy_magic_string_to_buffer (lit_magic_string_id_t, lit_utf8_byte_t *, lit_utf8_size_t);
|
||||
|
||||
#endif /* LIT_MAGIC_STRINGS_H */
|
||||
|
||||
Reference in New Issue
Block a user