jerryx_arg: add '\0' when transforming string (#1827)

Related issue: #1824

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
Zidong Jiang 2017-05-22 08:32:20 +08:00 committed by GitHub
parent 5e28bfc28a
commit eb2af2d2a6
2 changed files with 10 additions and 8 deletions

View File

@ -145,16 +145,20 @@ static jerry_value_t
jerryx_arg_string_common_routine (jerry_value_t js_arg, /**< JS arg */
const jerryx_arg_t *c_arg_p) /**< native arg */
{
jerry_char_t *target_p = (jerry_char_t *) c_arg_p->dest;
jerry_size_t target_buf_size = (jerry_size_t) c_arg_p->extra_info;
jerry_size_t size = jerry_string_to_char_buffer (js_arg,
(jerry_char_t *) c_arg_p->dest,
(jerry_size_t) c_arg_p->extra_info);
target_p,
target_buf_size);
if (size == 0)
if (size == 0 || size == target_buf_size)
{
return jerry_create_error (JERRY_ERROR_TYPE,
(jerry_char_t *) "The size of the buffer is not large enough.");
}
target_p[size] = '\0';
return jerry_create_undefined ();
} /* jerryx_arg_string_common_routine */

View File

@ -86,7 +86,7 @@ test_validator1_handler (const jerry_value_t func_obj_val __attribute__((unused)
bool arg1;
double arg2 = 0.0;
char arg3[5] = { 0 };
char arg3[5] = "1234";
jerry_value_t arg4 = jerry_create_undefined ();
jerryx_arg_t mapping[] =
@ -114,8 +114,7 @@ test_validator1_handler (const jerry_value_t func_obj_val __attribute__((unused)
TEST_ASSERT (!jerry_value_has_error_flag (is_ok));
TEST_ASSERT (arg1);
TEST_ASSERT (arg2 == 10.5);
TEST_ASSERT (arg3[0] == 'a' && arg3[1] == 'b'
&& arg3[2] == 'c' && arg3[4] == '\0');
TEST_ASSERT (strcmp (arg3, "abc") == 0);
TEST_ASSERT (jerry_value_is_function (arg4));
}
else if (validator1_count == 1)
@ -123,8 +122,7 @@ test_validator1_handler (const jerry_value_t func_obj_val __attribute__((unused)
TEST_ASSERT (!jerry_value_has_error_flag (is_ok));
TEST_ASSERT (arg1);
TEST_ASSERT (arg2 == 10.5);
TEST_ASSERT (arg3[0] == 'a' && arg3[1] == 'b'
&& arg3[2] == 'c' && arg3[4] == '\0');
TEST_ASSERT (strcmp (arg3, "abc") == 0);
TEST_ASSERT (jerry_value_is_undefined (arg4));
}
else