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
+7 -9
View File
@@ -290,10 +290,10 @@ Copy string characters to specified buffer, append zero character at end of the
**Prototype**
```c
ssize_t
jerry_api_size_t
jerry_api_string_to_char_buffer (const jerry_api_string_t * string_p,
char * buffer_p,
ssize_t buffer_size);
jerry_api_size_t buffer_size);
```
- `string_p` - pointer to a string;
@@ -319,15 +319,13 @@ jerry_api_string_to_char_buffer (const jerry_api_string_t * string_p,
if (is_string) {
// neg_req_sz would be negative, as zero-size buffer is insufficient for any string
ssize_t neg_req_sz = jerry_api_string_to_char_buffer (val.string_p,
NULL,
0);
char * str_buf_p = (char*) malloc (-neg_req_sz);
jerry_api_size_t req_sz = jerry_api_get_string_size (val.string_p);
char * str_buf_p = (char*) malloc (req_sz);
// sz would be -neg_req_sz
size_t sz = jerry_api_string_to_char_buffer (val.string_p,
str_buf_p,
-neg_req_sz);
jerry_api_size_t sz = jerry_api_string_to_char_buffer (val.string_p,
str_buf_p,
req_sz);
printf ("%s", str_buf_p);